Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 MY first game- problems
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Original




PostPosted: Mon May 11, 2009 12:42 pm   Post subject: MY first game- problems

Hi, I'm new to turing and i'm trying to make a game where homer simpson has to try to collect the falling donuts, and to avoid the flander's heads. I have two problems, my game is getting very flashy (flickery) and i dont understand how to work the collision detection between the donuts and homer simpson.

Thanks, here is the code Cool



var x, y : int
x := 100

var movex : int
var movec : int
var homer : int := Pic.FileNew ("homer.bmp")

y := 100

var chars : array char of boolean
process donutfall
loop

randint (movec, 0, 255)
randint (movex, 0, maxx)

for decreasing i : maxy .. 0 by 15

Draw.FillOval (movex, i, 20, 20, movec)
Draw.FillOval (movex, i, 7, 7, white)
delay (20)
cls
View.UpdateArea (0, 0, 500, 400)
if i <= 20 then
delay (1000)
end if
end for
end loop
end donutfall

procedure homermove
loop
Input.KeyDown (chars)

if chars (KEY_UP_ARROW) then
y := y + 6
Pic.Draw (homer, x, y, 0)
end if
if chars (KEY_RIGHT_ARROW) then

x := x + 6
if x>600 then
x:= 600
end if
Pic.Draw (homer, x, y, 0)
end if
if chars (KEY_LEFT_ARROW) then
x := x - 6

if x < 0 then
x:= 0
end if

end if
if chars (KEY_DOWN_ARROW) then
y := y - 6
if y < 0 then
y := 0
end if
Pic.Draw (homer, x, y, 0)
end if



Pic.Draw (homer, x, y, 0)
delay (15)
cls
View.UpdateArea (0, 0, 500, 400)
end loop
end homermove

fork donutfall
homermove
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Mon May 11, 2009 12:53 pm   Post subject: RE:MY first game- problems

to use View.Update you need to set your view to the offscreenonly mode first. Though the use of processes breaks it anyway, so it will still flash, or simply not draw certain parts at all.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
milkislife




PostPosted: Mon May 11, 2009 1:00 pm   Post subject: RE:MY first game- problems

for donut detection, I suggest the comman whatdotcolor.
for example: if x and y are bottem left corner

Use that in an if statement.

if whatdotcolor(x+(halfway through homer),y+(height of homer + 1) = (color of donut) then

That there ^^ would check 1 above the middle top of homer. If it equaled the color of the donut then you could have score := score + 1
Tony




PostPosted: Mon May 11, 2009 1:13 pm   Post subject: Re: RE:MY first game- problems

milkislife @ Mon May 11, 2009 1:00 pm wrote:
I suggest the comman whatdotcolor.

Don't listen to milkislife. If you know the position where to check for colours, you can easily just calculate the distance and see if two points are close enough to collide.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Dusk Eagle




PostPosted: Mon May 11, 2009 2:05 pm   Post subject: Re: RE:MY first game- problems

Tony @ Mon May 11, 2009 2:13 pm wrote:

If you know the position where to check for colours, you can easily just calculate the distance and see if two points are close enough to collide.


I'm pretty sure people have helped you with this twice before, so look there. Also, *ask your teacher!* Having a real person right there to help you can be indispensable when you are completely new to something (such as programming).
Original




PostPosted: Mon May 11, 2009 5:45 pm   Post subject: Re: MY first game- problems

So is there any other ways i can run this without using processes? Because my picture wouldn't appear at the same time the donuts fall if i dont use the command process. And View.Update doesnt work if i use processes.
Tony




PostPosted: Mon May 11, 2009 5:55 pm   Post subject: RE:MY first game- problems

You don't need processes, just use a single "main-loop" structure
code:

loop
   % get input
   % act on input
   % update graphics
end loop
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Original




PostPosted: Mon May 11, 2009 8:15 pm   Post subject: Re: MY first game- problems

I tried it with one loop but homer keeps appearing after the donuts fall down. After the new donut appears, the picture of homer goes away. I cant get homer's picture to run seperately.
Sponsor
Sponsor
Sponsor
sponsor
Dusk Eagle




PostPosted: Mon May 11, 2009 8:27 pm   Post subject: Re: MY first game- problems

We need code of what you've attempted if anyone is going to help you. Be sure to format it like this:
code:

[syntax="turing"]
%%%code here%%%
[/syntax]
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: