Jump to content
IGNORED

Little help with my code


HatefulGravey

Recommended Posts

I'm playing with bB while I'm sitting around this week. I have 2 weeks off for vacation so I'm enjoying that time the best way I know how :D .

 

I decided to try to make a simple space shooter style game just to cover the basics, and in the end decided to do it backwards. What if you are the "bad guy" and you are just trying to get home and the normal "good guy" is just in your way stopping that. I'm just calling it Home right now. You are just trying to get home and the space shooter is stopping that. I have more plans than the program covers right now but I have a strange problem I want to work on before I move too far forward.

 

As the code stands the point is the have the player move faster while holding the fire button. This works most of the time, but if you are moving up and left of down and right the code does nothing. It works if you go up and right or down and left so I'm a bit lost. I'm also sure there is a more efficient way to code the player move moment than I have used. So if you have pointers please fill me in.

 

 

 rem batari Basic Program
rem created 10/12/2012 10:26:46 PM by Visual bB Version 1.0.0.548

playfield:
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
end


player0:
%11100111
%10111101
%10100101
%01011010
%00100100
%01011010
%10011001
%10000001
end

player1:
%00011000
%00011000
%00111100
%01111110
%11111111
%11111111
%11111111
%11111111
end

COLUBK=$45

player0x=76:player0y=78
player1x=76:player1y=14

playermove
if joy0fire then c=5 else c=1
if joy0up then player0y=player0y-c
if joy0down then player0y=player0y+c
if joy0left then player0x=player0x-c
if joy0right then player0x=player0x+c
if player0x>133 then player0x=133
if player0x<21 then player0x=21
if player0y>80 then player0y=80
if player0y<14 then player0y=14
if player0y<15 then score=score+1: player0x=76:player0y=78
end

badguymove
if player0x>player1x then player1x=player1x+1
if player0x<player1x then player1x=player1x-1
end

main
drawscreen
goto playermove
goto badguymove
goto main

 

Its all very simple right now, I'm trying to learn here. I have played with the code a bunch and the functions have been written a few ways, this is the way that seems to make the most since to me, but it seems to me there is a better way to code player movement, and like I said, it isn't working right at the moment.

 

I have to learn missile and collision stuff next, so that isn't in the code yet. Thank you for taking a look at my code.

Link to comment
Share on other sites

I'm very far from an expert but it appears

to me to work just fine.

 

I don't see the purpose of the end statements

after the playermove and badguymove blocks.

 

Are you sure you don't want subroutines

(with returns instead of ends and gosubs instead of

gotos)?

 

As it stands now your code runs in a loop from

playermove to the goto playermove statement.

It never gets to the goto badguymove and goto main

statements (as far as I can tell).

Link to comment
Share on other sites

Are you sure you don't want subroutines

(with returns instead of ends and gosubs instead of

gotos)?

 

Agreed that it looks like the intent was to use subs. Something like...

 

rem batari Basic Program
rem created 10/12/2012 10:26:46 PM by Visual bB Version 1.0.0.548

playfield:
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
end


player0:
%11100111
%10111101
%10100101
%01011010
%00100100
%01011010
%10011001
%10000001
end

player1:
%00011000
%00011000
%00111100
%01111110
%11111111
%11111111
%11111111
%11111111
end

COLUBK=$45

player0x=76:player0y=78
player1x=76:player1y=14

main
drawscreen
gosub playermove
gosub badguymove
goto main

playermove
if joy0fire then c=5 else c=1
if joy0up then player0y=player0y-c
if joy0down then player0y=player0y+c
if joy0left then player0x=player0x-c
if joy0right then player0x=player0x+c
if player0x>133 then player0x=133
if player0x<21 then player0x=21
if player0y>80 then player0y=80
if player0y<14 then player0y=14
if player0y<15 then score=score+1: player0x=76:player0y=78
return

badguymove
if player0x>player1x then player1x=player1x+1
if player0x<player1x then player1x=player1x-1
return


Link to comment
Share on other sites

I see what you are getting at there. I'm not very good at this yet, and it has been a long time since basic was something on my mind. I'm glad I risked the embarrassment I did to list this. Already learning a pile. Thanks guys.

 

It reads like it should work just fine, but when run the program doesn't work right. The directions I mentioned in the first post don't work together. All this is about to be redone with the new information I have gathered put to use tomorrow. Maybe things will just work better that way.

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