Problem with Collision Detection

Understanding the language, error messages, etc.

Problem with Collision Detection

Postby reuta » Sat Feb 11, 2017 7:34 pm

Hello Everyone!

I am new here. I got my Gamebuino for christmas.
I was trying to program sort of a "duckhunt" game, where you need to shoot ducks.
There's a cross on the screen which the player can move to aim at the ducks.
I am currently only playing around, so ducks are just some small rectangles.
My code might be a bit messy. I am not an experienced programmer ( I am 15 years old going to high school).
A problem I encountered, was that when i pressed k to shoot, I can't kill the ducks. But I am aiming at them.
I think this is because i am doing something wrong with collision detection.
I tested everything with the web based gamebuino emulator.

Here's my code pasted: http://pastebin.com/raw/8T8JUcM0

Thank you in advance!

Adrian
reuta
 
Posts: 2
Joined: Sat Feb 11, 2017 7:22 pm

Re: Problem with Collision Detection

Postby wuuff » Sun Feb 12, 2017 12:25 pm

The byte data type is unsigned, which meant that when you assigned it a random value from -1 to 1, you were actually assigning it a value of 255, 0, or 1. It only took a few loops for the x position of the ducks to reach a few thousand. This looked normal because when the Gamebuino draws to the screen it uses unsigned bytes, and trying to draw something far off the screen causes those values to overflow, meaning it still drew the ducks in a place that looked right, even though their actual coordinates were in the thousands.

Try changing "byte dir;"in struct Duck to "char dir;". That should solve the problem. If you don't want to use char, you can also use "int8_t".

Your code is plenty clean and easy to understand. I would say it's quite good for a 15-year-old in high school. Good luck with your Gamebuino projects, and I hope you post some cool games in the future!
wuuff
 
Posts: 61
Joined: Sun Aug 28, 2016 6:05 am

Re: Problem with Collision Detection

Postby reuta » Mon Feb 13, 2017 3:29 pm

Thank you! This solved my problem.
reuta
 
Posts: 2
Joined: Sat Feb 11, 2017 7:22 pm


Return to Programming Questions

Who is online

Users browsing this forum: No registered users and 8 guests

cron