Jump to content
IGNORED

Need some programming help.


The average gamer

Recommended Posts

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.

Link to comment
Share on other sites

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-5

but 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 this

if player0y<10 then player0y=10
if player0y>85 then player0y=85

Now 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)
Link to comment
Share on other sites

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 __game

rem code is over

We have a big problem though, the player goes way to fast and doesn't look gird based at all...

So we need a variable

Right before any other code type this... dim _movement = a

This 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 = 1

Now 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 back

Here'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
Link to comment
Share on other sites

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. :P

Edited by mojofltr
Link to comment
Share on other sites

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

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...