Jump to content

Photo

Can someone explain this collision code in detail?

Batari Basic Help

10 replies to this topic

#1 Lolkiu64 OFFLINE  

Lolkiu64

    Space Invader

  • 24 posts

Posted Sat Jan 20, 2018 2:03 AM

For the new Max Maze game, I'm using Random Terrain's "ex_sprite_ball_missile_collision_prevention.bas" example to add the perfect collision. (It is a maze game after all)

However there are two things I need to ask you guys...

1. Could someone explain this part in detail, perhaps understanding it better can help with fixing bugs and glitches for my games using this code in the future.
(The example below is from Random Terrain's example, not my game)

 
   temp5 = (player0x-10)/4
 
   temp6 = (player0y-9)/8
 
   if temp5 < 34 then if pfread(temp5,temp6) then goto __Skip_Joy0_Up
 
   temp4 = (player0x-17)/4
 
   if temp4 < 34 then if pfread(temp4,temp6) then goto __Skip_Joy0_Up
 
   temp3 = temp5 - 1
 
   if temp3 < 34 then if pfread(temp3,temp6) then goto __Skip_Joy0_Up

2. As I've said my newest game is using the above code for collision, however unlike Random Terrain's 8x8 sprite in the example, this sprite is 3x6

Because of this sudden sprite size change, the game is going crazy, going left and up seems to be fine, but going right and down at the same time is awful. You can barley move around since the walls feel like they have the force pushing you away from them.

 Any help would be appreciated, Thanks


(When playing 2018_01_19_2349, make sure to press the fire button when you see a blank red screen to start the actual game)

Attached Files


Edited by Lolkiu64, Sat Jan 20, 2018 2:05 AM.


#2 Lewis2907 OFFLINE  

Lewis2907

    Moonsweeper

  • 266 posts
  • Location:Senatobia, MS

Posted Sat Jan 20, 2018 2:59 AM

This may help. It helped me some with collision.

http://atariage.com/...real-this-time/

I will take a look at your code, I'm not the best but I will give it a try this weekend, thanks.

#3 bogax OFFLINE  

bogax

    Dragonstomper

  • 761 posts

Posted Sat Jan 20, 2018 10:01 AM

this lets you step player0 around the screen while displaying

player0x in the left three score digits and player0y in the right three score digits

the sprite changes color when there's a collision with the playfield

 

bear in mind that the sprites are drawn upside down so this 3x6 sprite

is in the lower left corner of an 8x8 sprite definition

 

 

Attached Files



#4 bogax OFFLINE  

bogax

    Dragonstomper

  • 761 posts

Posted Sat Jan 20, 2018 6:35 PM

here I've inserted different collision code and changed the height of player0

 

the code is basically similar

it tests two corners of the player0 for each direction

to see if there's a playfield pixel in the way

 

so for example if you're moving right it tests the top right

corner of player0 against the bottom left of the PFpixel

and the bottom right of player0 against the top left of the PFpixel

 

 

Attached Files



#5 Random Terrain OFFLINE  

Random Terrain

    Visual batari Basic User

  • 28,744 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Sat Jan 20, 2018 7:09 PM

here I've inserted different collision code and changed the height of player0

 

the code is basically similar

it tests two corners of the player0 for each direction

to see if there's a playfield pixel in the way

 

so for example if you're moving right it tests the top right

corner of player0 against the bottom left of the PFpixel

and the bottom right of player0 against the top left of the PFpixel

 

 

 

I'll be gone for a day or two (more packing and moving), but when I get back, if your code uses less space or cycles or both, I'll update the examples on the bB page.



#6 Lolkiu64 OFFLINE  

Lolkiu64

    Space Invader

  • Topic Starter
  • 24 posts

Posted Sat Jan 20, 2018 9:41 PM

@Lewis2907: Thanks, even though the topic looks pretty long, I'll give it a shot.

@bogax: Wow, I forgot about the sprites being drawn upside down, I guess that shows how new I am at this, but I'll soon get to your level I'm sure. I'll be sure to check out sprite_postion.bas and of course the Max's Maze Mod. Speaking of this mod, I'm planning on making a whole series of Max's Maze games, each one helps me learn something new in bB, for example the first game is collision, the second will introduce sounds, animations, and so on. Would you mind if I added your mod into the list of Max's Maze games? (Just as a mini example, and of course I'll give you credit)

@Randon Terrain: I know you weren't replying to me but, good luck moving  :thumbsup:



#7 Lolkiu64 OFFLINE  

Lolkiu64

    Space Invader

  • Topic Starter
  • 24 posts

Posted Sat Jan 20, 2018 10:59 PM

Just tried out bogax's example, it's awesome, Thanks for your help.  ;-)



#8 Lewis2907 OFFLINE  

Lewis2907

    Moonsweeper

  • 266 posts
  • Location:Senatobia, MS

Posted Sun Jan 21, 2018 9:22 PM

Lolkiu64,

 

Thanks to Bogax code I was able to adjust some of my stuff. I did add the feature of speed control (based upon RT's Code) if that helps. That way your sprite speed is adjustable.

 

   ;***************************************************************
   ;
   ;  Don't move right if pfpixel is in the way.
   ; 
   if joy0right then _P0_L_R = _P0_L_R + .5 : then left
   temp3 = (player0x - 14)/4 : temp4 = (player0y - 6)/8
   if pfread(temp3, temp4) then _P0_L_R = _P0_L_R - .5 : then down
   temp3 = (player0x - 14)/4 : temp4 = (player0y - 1)/8
   if pfread(temp3, temp4) then _P0_L_R = _P0_L_R - .5 : then down

 

(Just adjust all the .5 to what ever you need. 1.5; 1.8; .9 etc.) I did try to add another section, but got an error to detect the middle of the sprite. My thought there was if you can detect the middle of the sprite. Why not code it for the entire sprite. I know it will eat up space but then I think you have 100% collision. What I tried and it didn't compile. temp4 = (player0y - 3)/8 should detect the middle of the sprite, i think.

 

   ;***************************************************************
   ;
   ;  Don't move right if pfpixel is in the way.
   ;
   if joy0right then _P0_L_R = _P0_L_R + .5 : then left

 

   temp3 = (player0x - 14)/4 : temp4 = (player0y - 6)/8
   if pfread(temp3, temp4) then _P0_L_R = _P0_L_R - .5 : then down

 

   temp3 = (player0x - 14)/4 : temp4 = (player0y - 3)/8
   if pfread(temp3, temp4) then _P0_L_R = _P0_L_R - .5 : then down

 

   temp3 = (player0x - 14)/4 : temp4 = (player0y - 1)/8
   if pfread(temp3, temp4) then _P0_L_R = _P0_L_R - .5 : then down

 

I am working on the Multisprite version which is attached. Hopefully Bogax or someone can adjust the code around to work. The left and right detection works. I'm having trouble with the up and down portions.

 

The issue I see even in the above program is that they both use only one pixel for detection which is great, but at times the sprite will cut corners and not have the 100% true detection. This is still better that the bouncy detection that I first learned how to use. Hope these help in your game development, thanks. 

Attached Files


Edited by Lewis2907, Sun Jan 21, 2018 9:24 PM.


#9 Coolcrab OFFLINE  

Coolcrab

    Moonsweeper

  • 325 posts
  • Location:Stockholm

Posted Mon Jan 22, 2018 6:20 AM

This seems very relevant to my problem, so please allow me to highjack the thread a little bit. I got my game to work using similar conversions but the collision only seems to registers if the player moves into the wall and not if the wall scrolls into the player. Is this a known problem? And is there any way around it?



#10 bogax OFFLINE  

bogax

    Dragonstomper

  • 761 posts

Posted Mon Jan 22, 2018 7:44 AM

Lolkiu64,

 

Thanks to Bogax code I was able to adjust some of my stuff. I did add the feature of speed control (based upon RT's Code) if that helps. That way your sprite speed is adjustable.

 

   ;***************************************************************
   ;
   ;  Don't move right if pfpixel is in the way.
   ; 
   if joy0right then _P0_L_R = _P0_L_R + .5 : then left
   temp3 = (player0x - 14)/4 : temp4 = (player0y - 6)/8
   if pfread(temp3, temp4) then _P0_L_R = _P0_L_R - .5 : then down
   temp3 = (player0x - 14)/4 : temp4 = (player0y - 1)/8
   if pfread(temp3, temp4) then _P0_L_R = _P0_L_R - .5 : then down

 

(Just adjust all the .5 to what ever you need. 1.5; 1.8; .9 etc.) I did try to add another section, but got an error to detect the middle of the sprite. My thought there was if you can detect the middle of the sprite. Why not code it for the entire sprite. I know it will eat up space but then I think you have 100% collision. What I tried and it didn't compile. temp4 = (player0y - 3)/8 should detect the middle of the sprite, i think.

 

   ;***************************************************************
   ;
   ;  Don't move right if pfpixel is in the way.
   ;
   if joy0right then _P0_L_R = _P0_L_R + .5 : then left

 

   temp3 = (player0x - 14)/4 : temp4 = (player0y - 6)/8
   if pfread(temp3, temp4) then _P0_L_R = _P0_L_R - .5 : then down

 

   temp3 = (player0x - 14)/4 : temp4 = (player0y - 3)/8
   if pfread(temp3, temp4) then _P0_L_R = _P0_L_R - .5 : then down

 

   temp3 = (player0x - 14)/4 : temp4 = (player0y - 1)/8
   if pfread(temp3, temp4) then _P0_L_R = _P0_L_R - .5 : then down

 

I am working on the Multisprite version which is attached. Hopefully Bogax or someone can adjust the code around to work. The left and right detection works. I'm having trouble with the up and down portions.

 

The issue I see even in the above program is that they both use only one pixel for detection which is great, but at times the sprite will cut corners and not have the 100% true detection. This is still better that the bouncy detection that I first learned how to use. Hope these help in your game development, thanks. 

 

 

you could have a look at this

 

 

 

Attached Files


Edited by bogax, Mon Jan 22, 2018 8:22 AM.


#11 Lolkiu64 OFFLINE  

Lolkiu64

    Space Invader

  • Topic Starter
  • 24 posts

Posted Tue Jan 23, 2018 12:51 AM

@Coolcrab feel free to highjack any topic I start

@Bogax Thanks to you, I finished my Max's Maze Deluxe game, also I'll be sure to try out collision_prevention_13.bas

(P.S. I'm giving you special credit)  :-D







Also tagged with one or more of these keywords: Batari Basic, Help

0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users