Jump to content
IGNORED

Random position glitch


Captain Spazer

Recommended Posts

I've hit another snag. In this game, when player1 is hit with missile0 it goes offscreen and gets a random y position and a semi random x position. Anyway, that's what's supposed to happen. But instead of going offscreen too determine x and y position it does it onscreen and it makes for a weird rolling effect on the enemy sprite, what did I do wrong here? It works for player 2 and player 3.

 

 

The code that's glitchy. I know it's extremely big and clunky, but it was the only way I could make hit detection work for all 3 player sprites, and I'm out of variables. On a sidenote: Is there any tricks on using less variables?

  q=player2x-8
 r=player2x+18
 s=player2y+1
 t=player2y-8

 u=player3x-8
 d=player3x+18
 v=player3y+1
 w=player3y-8


 rem makes player1 move
 if n=0 then player1x=140 : n=2
 if n=2 then _P1_L_R=_P1_L_R-0.25
 if n=1 then player1x=5 : n=3
 if n=3 then _P1_L_R=_P1_L_R+0.25
 rem random location for player1
 if player1x<=5 then player1x=255 : player1y=255 : n=(rand&1) : player1y=rand
 if player1x>=140 then player1x=255 : player1y=255 : n=(rand&1) : player1y=rand

 if player1y<20 then player1x=255 : player1y=255 : n=(rand&1) : player1y=rand
 if player1y>80 then player1x=255 : player1y=255 : n=(rand&1) : player1y=rand

 rem makes player2 move
 if o=0 then player2x=140 : o=2
 if o=2 then _P2_L_R=_P2_L_R-0.50
 if o=1 then player2x=5 : o=3
 if o=3 then _P2_L_R=_P2_L_R+0.50

 rem random location for player2
 if player2x<=5 then player2x=255 : player2y=255 : o=(rand&1) : player2y=rand
 if player2x>=140 then player2x=255 : player2y=255 : o=(rand&1) : player2y=rand

 if player2y<20 then player2x=255 : player2y=255 : o=(rand&1) : player2y=rand
 if player2y>80 then player2x=255 : player2y=255 : o=(rand&1) : player2y=rand

 rem makes player3 move
 if p=0 then player3x=140 : p=2
 if p=2 then _P3_L_R=_P3_L_R-1.00
 if p=1 then player3x=5 : p=3
 if p=3 then _P3_L_R=_P3_L_R+1.00

 rem random location for player3
 if player3x<=5 then player3x=255 : player3y=255 : p=(rand&1) : player3y=rand
 if player3x>=140 then player3x=255 : player3y=255 : p=(rand&1) : player3y=rand

 if player3y<20 then player3x=255 : player3y=255 : p=(rand&1) : player3y=rand
 if player3y>80 then player3x=255 : player3y=255 : p=(rand&1) : player3y=rand

rem shoot player1
 if collision(missile0,player1) && missile0y=player1y then player1x=254 : player1y=254 : j=0 : score=score+10 : c=c+1
 if collision(missile0,player1) && missile0y=player1y+1 then player1x=254 : player1y=254 : j=0 : score=score+5 : c=c+1
 if collision(missile0,player1) && missile0y=player1y+2 then player1x=254 : player1y=254 : j=0 : score=score+5 : c=c+1
 if collision(missile0,player1) && missile0y=player1y+3 then player1x=254 : player1y=254 : j=0 : score=score+5 : c=c+1
 if collision(missile0,player1) && missile0y=player1y+4 then player1x=254 : player1y=254 : j=0 : score=score+5 : c=c+1
 if collision(missile0,player1) && missile0y=player1y+5 then player1x=254 : player1y=254 : j=0 : score=score+5 : c=c+1
 if collision(missile0,player1) && missile0y=player1y+6 then player1x=254 : player1y=254 : j=0 : score=score+5 : c=c+1
 if collision(missile0,player1) && missile0y=player1y+7 then player1x=254 : player1y=254 : j=0 : score=score+5 : c=c+1
 if collision(missile0,player1) && missile0y=player1y+8 then player1x=254 : player1y=254 : j=0 : score=score+5 : c=c+1

 if collision(missile0,player1) && missile0y=player1y-1 then player1x=254 : player1y=254 : j=0 : score=score+5 : c=c+1
 if collision(missile0,player1) && missile0y=player1y-2 then player1x=254 : player1y=254 : j=0 : score=score+5 : c=c+1
 if collision(missile0,player1) && missile0y=player1y-3 then player1x=254 : player1y=254 : j=0 : score=score+5 : c=c+1
 if collision(missile0,player1) && missile0y=player1y-4 then player1x=254 : player1y=254 : j=0 : score=score+5 : c=c+1
 if collision(missile0,player1) && missile0y=player1y-5 then player1x=254 : player1y=254 : j=0 : score=score+5 : c=c+1
 if collision(missile0,player1) && missile0y=player1y-6 then player1x=254 : player1y=254 : j=0 : score=score+5 : c=c+1
 if collision(missile0,player1) && missile0y=player1y-7 then player1x=254 : player1y=254 : j=0 : score=score+5 : c=c+1
 if collision(missile0,player1) && missile0y=player1y-8 then player1x=254 : player1y=254 : j=0 : score=score+5 : c=c+1

This code works for player 2 & player 3:

 rem shoot player2
 if missile0x>q && missile0x<r && missile0y<s && missile0y>t then player2x=255 : player2y=255 : j=0 : score=score+10 : c=c+1

 rem shoot player3
 if missile0x>u && missile0x<d && missile0y<v && missile0y>w then player3x=255 : player3y=255 : j=0 : score=score+50 : c=c+1

The entire code: Monster_Safari.bas

Edited by Captain Spazer
Link to comment
Share on other sites

I've hit another snag. In this game, when player1 is hit with missile0 it goes offscreen and gets a random y position and a semi random x position. Anyway, that's what's supposed to happen. But instead of going offscreen too determine x and y position it does it onscreen and it makes for a weird rolling effect on the enemy sprite, what did I do wrong here? It works for player 2 and player 3.

 

 

The code that's glitchy. I know it's extremely big and clunky, but it was the only way I could make hit detection work for all 3 player sprites, and I'm out of variables. On a sidenote: Is there any tricks on using less variables?

  q=player2x-8
 r=player2x+18
 s=player2y+1
 t=player2y-8

 u=player3x-8
 d=player3x+18
 v=player3y+1
 w=player3y-8


 rem makes player1 move
 if n=0 then player1x=140 : n=2
 if n=2 then _P1_L_R=_P1_L_R-0.25
 if n=1 then player1x=5 : n=3
 if n=3 then _P1_L_R=_P1_L_R+0.25
 rem random location for player1
 if player1x<=5 then player1x=255 : player1y=255 : n=(rand&1) : player1y=rand
 if player1x>=140 then player1x=255 : player1y=255 : n=(rand&1) : player1y=rand

 if player1y<20 then player1x=255 : player1y=255 : n=(rand&1) : player1y=rand
 if player1y>80 then player1x=255 : player1y=255 : n=(rand&1) : player1y=rand

 rem makes player2 move
 if o=0 then player2x=140 : o=2
 if o=2 then _P2_L_R=_P2_L_R-0.50
 if o=1 then player2x=5 : o=3
 if o=3 then _P2_L_R=_P2_L_R+0.50

 rem random location for player2
 if player2x<=5 then player2x=255 : player2y=255 : o=(rand&1) : player2y=rand
 if player2x>=140 then player2x=255 : player2y=255 : o=(rand&1) : player2y=rand

 if player2y<20 then player2x=255 : player2y=255 : o=(rand&1) : player2y=rand
 if player2y>80 then player2x=255 : player2y=255 : o=(rand&1) : player2y=rand

 rem makes player3 move
 if p=0 then player3x=140 : p=2
 if p=2 then _P3_L_R=_P3_L_R-1.00
 if p=1 then player3x=5 : p=3
 if p=3 then _P3_L_R=_P3_L_R+1.00

 rem random location for player3
 if player3x<=5 then player3x=255 : player3y=255 : p=(rand&1) : player3y=rand
 if player3x>=140 then player3x=255 : player3y=255 : p=(rand&1) : player3y=rand

 if player3y<20 then player3x=255 : player3y=255 : p=(rand&1) : player3y=rand
 if player3y>80 then player3x=255 : player3y=255 : p=(rand&1) : player3y=rand

rem shoot player1
 if collision(missile0,player1) && missile0y=player1y then player1x=254 : player1y=254 : j=0 : score=score+10 : c=c+1
 if collision(missile0,player1) && missile0y=player1y+1 then player1x=254 : player1y=254 : j=0 : score=score+5 : c=c+1
 if collision(missile0,player1) && missile0y=player1y+2 then player1x=254 : player1y=254 : j=0 : score=score+5 : c=c+1
 if collision(missile0,player1) && missile0y=player1y+3 then player1x=254 : player1y=254 : j=0 : score=score+5 : c=c+1
 if collision(missile0,player1) && missile0y=player1y+4 then player1x=254 : player1y=254 : j=0 : score=score+5 : c=c+1
 if collision(missile0,player1) && missile0y=player1y+5 then player1x=254 : player1y=254 : j=0 : score=score+5 : c=c+1
 if collision(missile0,player1) && missile0y=player1y+6 then player1x=254 : player1y=254 : j=0 : score=score+5 : c=c+1
 if collision(missile0,player1) && missile0y=player1y+7 then player1x=254 : player1y=254 : j=0 : score=score+5 : c=c+1
 if collision(missile0,player1) && missile0y=player1y+8 then player1x=254 : player1y=254 : j=0 : score=score+5 : c=c+1

 if collision(missile0,player1) && missile0y=player1y-1 then player1x=254 : player1y=254 : j=0 : score=score+5 : c=c+1
 if collision(missile0,player1) && missile0y=player1y-2 then player1x=254 : player1y=254 : j=0 : score=score+5 : c=c+1
 if collision(missile0,player1) && missile0y=player1y-3 then player1x=254 : player1y=254 : j=0 : score=score+5 : c=c+1
 if collision(missile0,player1) && missile0y=player1y-4 then player1x=254 : player1y=254 : j=0 : score=score+5 : c=c+1
 if collision(missile0,player1) && missile0y=player1y-5 then player1x=254 : player1y=254 : j=0 : score=score+5 : c=c+1
 if collision(missile0,player1) && missile0y=player1y-6 then player1x=254 : player1y=254 : j=0 : score=score+5 : c=c+1
 if collision(missile0,player1) && missile0y=player1y-7 then player1x=254 : player1y=254 : j=0 : score=score+5 : c=c+1
 if collision(missile0,player1) && missile0y=player1y-8 then player1x=254 : player1y=254 : j=0 : score=score+5 : c=c+1

This code works for player 2 & player 3:

 rem shoot player2
 if missile0x>q && missile0x<r && missile0y<s && missile0y>t then player2x=255 : player2y=255 : j=0 : score=score+10 : c=c+1

 rem shoot player3
 if missile0x>u && missile0x<d && missile0y<v && missile0y>w then player3x=255 : player3y=255 : j=0 : score=score+50 : c=c+1

The entire code: attachicon.gifMonster_Safari.bas

 

 

The Atari uses most of it's time drawing the screen

it has to do that periodically, at regular intervals

There's a little time left over after it draws the screen

before it needs to draw the screen again

That's when your game code runs

you call drawscreen and it waits for the next

interval and draws the screen then runs your code

and if your code takes to long it'll miss it's appointed time

but it won't draw the screen until you do a drawscreen in your code

so

 

 

 if player1x<=5 then player1x=255 : player1y=255 : n=(rand&1) : player1y=rand

 

it's never going to see player1y = 255 there because you immediately set player1y = rand

in order for player1y = 255 to have an effect on what's displayed you'd have to call

drawscreen after you set player1y = 255 but before you set player1y = rand

setting player1y = 255 is completely redundant there

 

 

 

since you set the variables q r s t u d v w at the beginning of main, and you only need them to persist

for a single line, use temp variables instead

 

 

 dim lb = temp6
 dim rb = temp5
 dim tb = temp4
 dim bb = temp3
 
 
 
 lb = player2x-8
 rb = player2x+18
 tb = player2y+1
 bb = player2y-8
 
 rem shoot the lion
 if missile0x > lb && missile0x < rb && missile0y < tb && missile0y > bb then player2x=255 : player2y=255 : j=0 : score=score+10 : c=c+1
 
 lb = player3x-8
 rb = player3x+18
 tb = player3y+1
 bb = player3y-8
 
 rem shoot the pig
 if missile0x > lb && missile0x < rb && missile0y < tb && missile0y > bb then player3x=255 : player3y=255 : j=0 : score=score+50 : c=c+1
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...