Dalta Posted February 17, 2019 Share Posted February 17, 2019 Hope it's ok that I create a new thread each time I need help, I figured it would help people in future search if they're stuck on something.Anyway, I've created bullets for the player to shoot and now I'm trying to get the bullets to disappear when they hit a wall. I admit that I don't fully understand peekchar, but I get weird behaviour around line 29 in the below code.Before I put in the peekchar code, the bullets shoot from the player in whatever direction they're moving, as expected, but when I put in those peekchar lines around line 29 below, I get behaviour I don't understand. The appearance or otherwise of the bullet seems to depend on the player's position when in theory, that shouldn't affect it at all. The bullets also only appear when the player is on a certain side of the screen, not when they are touching a certain character, which is what I thought peekchar does. In theory it should be the character underneath either the player or the bullet which affects behaviour, no? Everything works fine until I set what 'tempbx' and 'tempby' are for the peekchar function. I put in a debug line which plots another face sprite which should match the same conditions as the bullet, but it appears at different times, seemingly random. On one run through the game crashed and plotted out a load of numbers at the top of the screen (this happened before during a different bug when I had mis-assigned a variable. I went through several times to make sure I hadn't done that this time and it doesn't look like it. It seems like there's something about peekchar that I don't understand. I tried to create a gif to illustrate the issue but apparently it's not allowed.My abridged code looks like the following: set collisionwrap on set doublewide on <assign variables> ; this next line is copied from Atarius Maximus's code dim screenram = $2200 : rem to $24EF (20*12=240 bytes) rem $24F0 to $27FF are free ;screen0map is the name of the map I made with alphachars memcpy screenram screen0map 240 plotmap screenram 1 0 0 20 12 savescreen main pprevx=playerx: pprevy=playery <movement code> if joy0fire0 && btimer=0 then gosub bullInit ; *** Plotting and Moving Bullets if firecon>10 then firecon=firecon-1 for x=0 to firecon ;giving variables to the bullets, in order to work in the if statement bx=bullx[x]: by=bully[x] ;check if the Bullet has hit a wall tempbx=bx/16:tempby=by/8 ;the bullets stop plotting for some reason after I enter this line tempchar2=peekchar(screenram,tempbx,tempby,20,12) if player_bullets[x]=1 && tempchar2=2 then player_bullets[x]=0 if tempchar2=2 then plotsprite face1 0 0 50 ;this is a debug line, though has weird behaviour too ;if the bullet is active, plot it and move it depending on it's direction for the next frame if player_bullets[x]=1 then plotsprite bullet 0 bx by: bullx[x]=bullx[x]+bdr[x]: bully[x]=bully[x]+bdd[x] next <some other code to prevent player moving off screen> if btimer>0 then btimer=btimer-1 plotsprite face1 0 playerx playery drawscreen goto main bullInit ;gives initial bullet variables bullx[firecon]=playerx: bully[firecon]=playery ; sets initial bullet coords at the player's coords player_bullets[firecon]=1 ;this basically sets the bullet to be active bdd[firecon]=playery-pprevy ;this sets the up/down velocity of the bullet depending on the player's movement bdr[firecon]=playerx-pprevx ;the same as above for left/right firecon=firecon+1 ; firecon keeps track of how many bullets there are btimer=10 ;this prevents too many bullets being plotted too quickly return ;checks for collision when player moves down checkmovedown tempx=(playerx+1)/8 tempy=(playery+8)/16 tempchar1=peekchar(screenram,tempx,tempy,20,12) if tempchar1=2 then return playery=playery+2:return <other code for player collision detection> alphachars ' abcdefghijklmnopqrstuvwxyz!@#$%^&*()_+-=[]{}:";<>,.?/' alphadata screen0map tileset_blanks2 ' ' ' ' 'aaaaaa aaaaaaaaa' ' ' ' aaaa ' ' aaaaaa ' ' ' ' aaaaa ' ' ' 'aaaaaaaaaa aaaa' ' ' ' ' end Thanks as always for any help. Quote Link to comment Share on other sites More sharing options...
RevEng Posted February 17, 2019 Share Posted February 17, 2019 You've mixed up the X and Y division factors, for the sprite to character coordinate conversion. Instead of "tempbx=bx/16:tempby=by/8" try "tempbx=bx/8:tempby=by/16" Quote Link to comment Share on other sites More sharing options...
Dalta Posted February 18, 2019 Author Share Posted February 18, 2019 Thank you for your help, that wasn't actually the error, I was still getting weird behaviour after I fixed the problem you mentioned. But I moved the line bx=bullx[x]: by=bully[x] to go after the peekchar lines (here:tempbx=bx/8:tempby=by/16tempchar2=peekchar(screenram,tempbx,tempby,20,12)if player_bullets[x]=1 && tempchar2=2 then player_bullets[x]=0if tempchar2=2 then plotsprite face1 0 0 50) and I got improved behaviour (though I don't understand why, it's like the latter lines above affected the assignment of bx and/or by). But anyway, I think I'm on to something here and I will pursue this for a while. If I need further help I will come back, thanks so much. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.