The average gamer Posted December 16, 2017 Share Posted December 16, 2017 So I'm pretty new to batari basic and I just wanted to know how you make so that when the player moves it "snaps" into place, kinda like in "Turmoil"? Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted December 16, 2017 Share Posted December 16, 2017 Instead of moving a sprite one pixel at a time, you'd move it more than that, like 5 or 10 or whatever you need. Quote Link to comment Share on other sites More sharing options...
The average gamer Posted December 16, 2017 Author Share Posted December 16, 2017 (edited) Ok I tried that, but it only made it go faster, did I do something wrong? Heres the code: if joy0down then player0y=player0y+5 if joy0up then player0y=player0y-5 Edited December 16, 2017 by The average gamer Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted December 16, 2017 Share Posted December 16, 2017 The larger the number, the faster it's going to move from one spot to another. If you want it to jump to a spot and sit there for a while before moving to the next spot, use a variable to make a counter so it can't move to the next position until the enough time has gone by. Quote Link to comment Share on other sites More sharing options...
The average gamer Posted December 16, 2017 Author Share Posted December 16, 2017 Aaaand how do you do that? Quote Link to comment Share on other sites More sharing options...
The average gamer Posted December 16, 2017 Author Share Posted December 16, 2017 (edited) Oh btw, do you think a game about packing random objects coming at random speeds on conveior belts would be fun? Edited December 16, 2017 by The average gamer Quote Link to comment Share on other sites More sharing options...
Mountain King Posted December 16, 2017 Share Posted December 16, 2017 You probably have to set up a data table something like this: (the data table must be outside your loop but in the same bank) data _position 0,10,20,30,40,50,... etc end player0y=_position[a] if joy0down then a=a+1 if joy0up then a=a-1 Quote Link to comment Share on other sites More sharing options...
JC Software Posted December 17, 2017 Share Posted December 17, 2017 I can tell you completely new, so I'll help you out as basic as possible, but make sure to teach yourself if your really serious about this.First we make the player move by pressing up or down on the joystick if joy0down then player0y=player0y+5 if joy0up then player0y=player0y-5but wait... we don't him off screen now do we Looking at random terrain's (move sprite) example we known the boundaries of the screen for vertical movement would be 9-88. Since were moving by 5, try thisif player0y<10 then player0y=10if player0y>85 then player0y=85Now we can't go off screen and were moving like a grid in a way... but when we hold the joystick we move across these points too fast!(I'll be back for part 2) Quote Link to comment Share on other sites More sharing options...
JC Software Posted December 17, 2017 Share Posted December 17, 2017 Ok so here's the example: rem 9 for top, 88 for bottom player0: %10011001 %01000010 %00100100 %10011001 %10011001 %00100100 %01000010 %10011001 end player0x = 50 : player0y = 50 __game COLUP0=$82 if joy0up then player0y = player0y-5 if joy0down then player0y = player0y+5 if player0y < 10 then player0y = 10 if player0y > 85 then player0y = 85 drawscreen goto __gamerem code is overWe have a big problem though, the player goes way to fast and doesn't look gird based at all...So we need a variableRight before any other code type this... dim _movement = aThis will be our movement variable taking up variable "a"Now let's put it to use...We want to be able to move at the beginning so add this before __game -> _movement = 1 Also add this after COLUP0 --> if _movement = 0 then goto __game Now add a colon after the player movement commands like this... if joy0up then player0y = player0y-5 : _movement = 0 if joy0down then player0y = player0y+5 : _movement = 0 Now when you push on the joystick _movement will become 0, this will skip the movement commands and make the player not be able to move.Of course we want the player to move multiple times, so we need to add one final code strip... Add this after COLUP0 if !joy0up && !joy0down then _movement = 1Now everytime the joystick goes up or down, you only move 5 once...However the sprite seems to disappear whenever you hold up or down, I would fix that now but I have to eat dinner, so I'll be backHere's the full example... rem 9 for top, 88 for bottom dim _movement = a player0: %10011001 %01000010 %00100100 %10011001 %10011001 %00100100 %01000010 %10011001 end player0x = 50 : player0y = 50 _movement = 1 __game COLUP0=$82 if !joy0up && !joy0down then _movement = 1 if _movement = 0 then goto __game if joy0up then player0y = player0y-5 : _movement = 0 if joy0down then player0y = player0y+5 : _movement = 0 if player0y < 10 then player0y = 10 if player0y > 85 then player0y = 85 drawscreen goto __game Quote Link to comment Share on other sites More sharing options...
uosipa llamxew Posted December 17, 2017 Share Posted December 17, 2017 (edited) if you aren't worried about wasting some variables you might try something like this: dim newX=a dim newY=b def move=c[0] ; initialize player0x=64 : player0y=64 : newX=64 : newY=64 ; in your main loop if !joy0left && !joy0right && !joy0up && !joy0down then move=0 if !move && joy0left then newX=newX-16 : move=1 if !move && joy0right then newX=newX+16 : move=1 if !move && joy0up then newY=newY-16 : move=1 if !move && joy0down then newY=newY+16 : move=1 if newX>player0x then player0x=player0x+2 if newX<player0x then player0x=player0x-2 if newY>player0y then player0y=player0y+2 if newY<player0y then player0y=player0y-2 // edit I wrote this up before I read the reply above - which is probably a better solution. Edited December 17, 2017 by mojofltr Quote Link to comment Share on other sites More sharing options...
JC Software Posted December 19, 2017 Share Posted December 19, 2017 Actually I think Mountain King's version would be best Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted December 19, 2017 Share Posted December 19, 2017 If you want Turmoil movement where the sprite hops from spot to spot and keeps moving if the joystick is held up or down, I'd do something like this: ;*************************************************************** ; ; Variable aliases go here (DIMs). ; ;``````````````````````````````````````````````````````````````` ; Slows down the up and down joystick movement. ; dim _Joy_Slowdown = a ;*************************************************************** ; ; Defines the edges of the playfield for an 8 x 8 sprite. ; If your sprite is a different size, you`ll need to adjust ; the numbers. ; const _P_Edge_Top = 9 const _P_Edge_Bottom = 81 const _P_Edge_Left = 1 const _P_Edge_Right = 152 ;*************************************************************** ; ; Sets starting position of player0. ; player0x = 77 : player0y = 54 ;*************************************************************** ; ; Sets playfield color. ; COLUPF = $2C ;*************************************************************** ; ; Sets background color. ; COLUBK = 0 ;*************************************************************** ; ; Defines shape of player0 sprite. ; player0: %00111100 %01111110 %11000011 %10111101 %11111111 %11011011 %01111110 %00111100 end ;*************************************************************** ;*************************************************************** ; ; MAIN LOOP (MAKES THE PROGRAM GO) ; ; __Main_Loop ;*************************************************************** ; ; Sets color of player0 sprite. ; COLUP0 = $9C ;*************************************************************** ; ; Skips up and down joystick movement if slowdown counter has ; been activated. ; if _Joy_Slowdown then _Joy_Slowdown = _Joy_Slowdown - 1 : goto __Skip_Joy_UD ;*************************************************************** ; ; Moves player0 sprite up or down with the joystick while ; keeping the sprite within the playfield area. Since the ; sprite movement jumps so much, a slowdown counter is used. ; A higher counter number will make the sprite pause for a ; longer amount of time before jumping to the next position. ; Use a smaller counter number to make the sprite move faster. ; if joy0up && player0y > _P_Edge_Top then player0y = player0y - 9 : _Joy_Slowdown = 6 if joy0down && player0y < _P_Edge_Bottom then player0y = player0y + 9 : _Joy_Slowdown = 6 __Skip_Joy_UD ;*************************************************************** ; ; Moves player0 sprite left or right with the joystick while ; keeping the sprite within the playfield area. ; if joy0left && player0x > _P_Edge_Left then player0x = player0x - 1 if joy0right && player0x < _P_Edge_Right then player0x = player0x + 1 ;*************************************************************** ; ; Displays the screen. ; drawscreen ;*************************************************************** ; ; Jumps back to the beginning of the main loop. ; goto __Main_Loop the_average_gamer_ex_01_2017y_12m_18d_2132t.bin the_average_gamer_ex_01_2017y_12m_18d_2132t.bas 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.