images.......

Blitz3D Forums/Blitz3D Beginners Area/images.......

po(Posted 2003) [#1]
I am making a simple game that has an image of a track and an image of a car, everything works except the car goes under the track image when I want it to go over the image.
How do I solve this problem?

-Thanks


ford escort(Posted 2003) [#2]
you have to draw the track before draw the car so the car will be on top of the track


po(Posted 2003) [#3]
I hava tried that..... I have both the track and the car in the same while loop, the track doesn't move but the car does.
And I have the buffer set as back buffer.
It's like this:

SetBuffer BackBuffer()

While Not KeyHit(1)

DrawImage track,0,0

Flip
Cls

If KeyDown(203) Then car_x=car_x-1*car_speed
If KeyDown(205) Then car_x=car_x+1*car_speed
If KeyDown(200) Then car_y=car_y-1*car_speed
If KeyDown(208) Then car_y=car_y+1*car_speed
If car_x>750 Then car_x=750
If car_x<0 Then car_x=0
If car_y>550 Then car_y=550
If car_y<0 Then car_y=0
If KeyDown(203) Then DrawImage car_west,car_x,car_y
If KeyDown(205) Then DrawImage car_east,car_x,car_y
If KeyDown(200) Then DrawImage car_north,car_x,car_y
If KeyDown(208) Then DrawImage car_south,car_x,car_y


Wend


see a problem somewhere?


ford escort(Posted 2003) [#4]
in your code you draw the track then flip ten erase the screen then draw the car then in the next loop, draw the track on top of the car , flip , erase the screen
you may just change where you're flip the screen and erase it

SetBuffer BackBuffer() 
While Not KeyHit(1) 
DrawImage track,0,0 
If KeyDown(203) Then car_x=car_x-1*car_speed 
If KeyDown(205) Then car_x=car_x+1*car_speed 
If KeyDown(200) Then car_y=car_y-1*car_speed 
If KeyDown(208) Then car_y=car_y+1*car_speed 
If car_x>750 Then car_x=750 
If car_x<0 Then car_x=0 
If car_y>550 Then car_y=550 
If car_y<0 Then car_y=0 
If KeyDown(203) Then DrawImage car_west,car_x,car_y 
If KeyDown(205) Then DrawImage car_east,car_x,car_y 
If KeyDown(200) Then DrawImage car_north,car_x,car_y 
If KeyDown(208) Then DrawImage car_south,car_x,car_y 

Flip 
Cls 
Wend 

hope it help and work (not tested but should work)


po(Posted 2003) [#5]
Thanks, it worked.


ford escort(Posted 2003) [#6]
and below the same but a bit optimised hope you like :)
you don't need to retest the keys to know what image of the car you have to draw.

SetBuffer BackBuffer() 
While Not KeyHit(1) 
DrawImage track,0,0 
If KeyDown(203) :car_x=car_x-1*car_speed:carframe=car_west:endif
If KeyDown(205) :car_x=car_x+1*car_speed:carframe=car_east:endif
If KeyDown(200) :car_y=car_y-1*car_speed:carframe=car_north:endif 
If KeyDown(208) :car_y=car_y+1*car_speed:carframe=car_south:endif
If car_x>750 Then car_x=750 
If car_x<0 Then car_x=0 
If car_y>550 Then car_y=550 
If car_y<0 Then car_y=0 
DrawImage carframe,car_x,car_y 
Flip 
Cls 
Wend 



po(Posted 2003) [#7]
Problem..... The code above does not work.
Memory Access Violation.
Oh, and how do you make it so if two different keys were pressed, make it show an image?
Because I have a North East, North West, South East and South West image of the car now that I want to put on.
When you press the up cursor and left cursor at the same time I want it to show the North West image.


ford escort(Posted 2003) [#8]
Problem..... The code above does not work.
Memory Access Violation.

my bad, just add yjis line at the top of this part of the code
carframe=car_north

this give a default value to te carframe else when blitz goes on the drawimage command he can't found the image and do a memory access violation

Oh, and how do you make it so if two different keys were pressed, make it show an image?
Because I have a North East, North West, South East and South West image of the car now that I want to put on.
When you press the up cursor and left cursor at the same time I want it to show the North West image.


it's already in your question, use AND .
:)

If KeyDown(203) and keydown(200) :car_x=car_x-1*car_speed:car_y=car_y-1*car_speed:carframe=car_southwest:endif
If KeyDown(205) and keydown(200) :car_x=car_x+1*car_speed:car_y=car_y-1*car_speed:carframe=car_southeast:endif
If KeyDown(203) and keydown(208) :car_x=car_x-1*car_speed:car_y=car_y+1*car_speed:carframe=car_northwest:endif
If KeyDown(205) and keydown(208) :car_x=car_x+1*car_speed:car_y=car_y+1*car_speed:carframe=car_northeast:endif

note that your first code draw the car only if a key is pressed so if you don't move te car the car disapear of the screen


Ross C(Posted 2003) [#9]
It's always good to put the

while not keyhit(1)
  cls


  draw stuff
  flip
wend


cls at the top or just after the flip, and put the flip right at the end of the loop :D


po(Posted 2003) [#10]
Everything works fine now except I can't think of a way to keep the image when no keys are pressed.
Because when no keys are pressed it will automatically show the car_north image. :(
I don't think this: DrawImage carframe,car_x,car_y
works too well. :(
Anyone have a way of solving this?


ford escort(Posted 2003) [#11]
it's probably because you put the carframe=car_north IN the loop you have to put the command OUTSIDE THE LOOP
like below :)


carframe=car_north
SetBuffer BackBuffer() 
While Not KeyHit(1) 
DrawImage track,0,0 
If KeyDown(203) :car_x=car_x-1*car_speed:carframe=car_west:endif
If KeyDown(205) :car_x=car_x+1*car_speed:carframe=car_east:endif
If KeyDown(200) :car_y=car_y-1*car_speed:carframe=car_north:endif 
If KeyDown(208) :car_y=car_y+1*car_speed:carframe=car_south:endif
If KeyDown(203) and keydown(200) :car_x=car_x-1*car_speed:car_y=car_y-1*car_speed:carframe=car_southwest:endif
If KeyDown(205) and keydown(200) :car_x=car_x+1*car_speed:car_y=car_y-1*car_speed:carframe=car_southeast:endif
If KeyDown(203) and keydown(208) :car_x=car_x-1*car_speed:car_y=car_y+1*car_speed:carframe=car_northwest:endif
If KeyDown(205) and keydown(208) :car_x=car_x+1*car_speed:car_y=car_y+1*car_speed:carframe=car_northeast:endif
If car_x>750 Then car_x=750 
If car_x<0 Then car_x=0 
If car_y>550 Then car_y=550 
If car_y<0 Then car_y=0 
DrawImage carframe,car_x,car_y 
Flip 
Cls 
Wend 


it's a default value just usefull before any key was pressed to avoid the Memory Access Violation. error, after that the value will stay the last key you pressed...


po(Posted 2003) [#12]
Thanks, I don't know if you can but is there any way you could make it so if a certain colour of an image overlaps another image it does something?
Like say if the image of the car overlaps the green part of the track image?