|
Post by hiiamevil on Jan 20, 2008 12:48:18 GMT -5
alright im trying to make a adventure game with kirby
dim kirby, kirbyl, kirby2, i, d kirby = 16 kirby2 = 16 kirbyl = 16 for i = 0 to 34 for d = 17 to 24
color (0,255,0) locate i, d: print"-----" next next
while true: cls if ScanKeyDown (VK_LEFT) and kirby > 0 then kirby = kirby - 1 endif if ScanKeyDown (VK_RIGHT) and kirby2 < 37 then kirby2 = kirby2 + 1 endif if ScanKeyDown (VK_UP) and kirbyl > 0 then kirbyl = kirbyl - 1 Else color (255, 105, 180) locate kirby, 16: print "<(O_O <)" locate kirby2, 16: print "(> O_O)>" locate 16, kirbyl: print "<( O_O )>"
endif wend
now it may look retarded i know.... what i attempted to do is have kirby face different directions when walking or jumping instead it made 3 seperate kirbys.... idk how to make the jump kirby to return to the ground level of the other kirbys. idk how to show both the green grass(i,d) with the kirbys. i only want 1 kirby lol... so please help me out
|
|
|
Post by hiiamevil on Jan 20, 2008 13:06:40 GMT -5
oh i think im guna have to learn to tile map or w.e. that may solve one of my problems
|
|
|
Post by steven522 on Jan 21, 2008 12:33:06 GMT -5
Your best bet is to break out your program into more manageable "chunks". Use the subroutine ability in B4GL to break things down. Keep your game logic and screen drawing as separate routines. this makes it easy to adjust things later if you decide to jump from "text" to graphical tiles later.
' ---------------------------------------------------------------- ' Kirby text mode test program
' set buffered text mode for smoother screen refresh textmode (text_buffered)
' define Kirby "Actions" const Nothing = 0 const WalkLeft = 1 const WalkRight = 2 const JumpingUp = 3 const JumpingDown = 4
' create Kirby object Type KirbyObj Row as integer Column as integer Action as integer counter1 as integer End Type
' declare subroutines declare sub DrawGround() declare sub GetInput() declare sub DrawKirby() declare sub PerformAction()
' declare global variables dim Kirby as kirbyObj
' ---------------------------------------------------------------- ' main program logic
' set game startup values Kirby.column = 10 Kirby.row = 16 ' main loop do ' get user input and perfrom the actions GetInput() PerformAction() ' clear current screen and draw "graphics" cls DrawGround() DrawKirby() DrawText() ' set sleep timer to slow down the screen updates sleep( 35 ) loop ' end of program when user presses escape end
' ---------------------------------------------------------------- ' define subroutines
' draw ground routine Sub DrawGround() dim row as integer dim column as integer color (0,255,0) ' loop through the rows/columns drawing "ground" for column = 0 to 39 for row = 17 to 23 locate column, row print"*" next next End Sub
' Get user input routine Sub GetInput() ' set a default "nothing" action kirby.action = nothing ' check for a specific key press to activate an action if ScanKeyDown (VK_UP) then kirby.action = jumpingup endif if ScanKeyDown (VK_LEFT) then kirby.action = walkleft endif if ScanKeyDown (VK_RIGHT) then kirby.action = walkright endif End Sub
' Perfrom actions routine Sub PerformAction() ' check if user is making kirby jump up if kirby.action = jumpingup then ' if kirby is not off screen then let him go up if kirby.row > 0 then kirby.row = kirby.row - 1 endif ' otherwise if kirby is in midair from a jump elseif kirby.row < 16 then ' let kirby begin falling kirby.row = kirby.row + 1 kirby.action = jumpingdown endif ' check for walking and keep kirby on-screen if kirby.action = walkleft then if kirby.column > 0 then kirby.column = kirby.column - 1 endif endif if kirby.action = walkright then if kirby.column < 32 then kirby.column = kirby.column + 1 endif endif End Sub
' draw kirby routine Sub drawKirby() ' set the color and locat kirby's screen position color (255, 105, 180) locate kirby.column, Kirby.row ' draw kirby depending upon the current action if Kirby.action = nothing then print "<( O_O )>" end if if Kirby.action = walkleft then print "<(O_O <)" endif if Kirby.action = walkright then print "(> O_O)>" end if if Kirby.action = jumpingup then print "v( O.O )v" end if if Kirby.action = jumpingdown then print "^( O.O )^" end if End Sub
|
|
|
Post by hiiamevil on Jan 21, 2008 12:56:21 GMT -5
whoa i dont understand that code lol, but it works so thnx man
|
|
|
Post by steven522 on Jan 21, 2008 14:00:30 GMT -5
Well, what do you not understand about it? Is there a specific command or just the structure. I thought I had things commented pretty well.
|
|
|
Post by hiiamevil on Jan 21, 2008 19:13:00 GMT -5
commented greatly its just im not use to that type of commands. like anything sub,declare, all that other not noobie stuff lol...
|
|
|
Post by steven522 on Jan 21, 2008 19:38:28 GMT -5
OK. Well just copy/paste the stuff between each sub/endsub in place of the actual call to the sub. It will be a little rough looking but no reason it wouldn't work straight through.
|
|
|
Post by Nicky Peter Hollyoake on Jan 21, 2008 21:29:23 GMT -5
TextMode(TEXT_BUFFERED) SetTextScroll(FALSE)
Dim Kirby$(2) Dim KirbyPos(1) Dim KirbyJump Dim CURRENT_KIRBY Dim X, Y 'Kirbys actions Kirby$(0) = "<( O_O )>" 'Standing still Kirby$(1) = "(> O_O )>" 'Moving right Kirby$(2) = "<( O_O <)" 'Moving left
'Kirbys starting position KirbyPos(1) = 19
While TRUE: CLS
'Kirbys controls if ScanKeyDown (VK_LEFT) AND KirbyPos(0) > 0 Then KirbyPos(0) = (KirbyPos(0) - 1) CURRENT_KIRBY = 2
Elseif ScanKeyDown (VK_RIGHT) AND KirbyPos(0) < TextCols() - Len(Kirby$(CURRENT_KIRBY)) Then KirbyPos(0) = (KirbyPos(0) + 1) CURRENT_KIRBY = 1
Else CURRENT_KIRBY = 0 Endif
if ScanKeyDown (VK_UP) AND Not KirbyJump AND KirbyPos(1) = 19 Then KirbyJump = TRUE
Else
if Not KirbyJump Then if KirbyPos(1) < 19 Then KirbyPos(1) = KirbyPos(1) + 1 Endif Endif Endif
if KirbyJump Then KirbyPos(1) = KirbyPos(1) - 1
if KirbyPos(1) < 15 Then KirbyJump = FALSE Endif Endif
'Draw Kirby Color (255, 105, 180) 'Pink color Locate KirbyPos(0), KirbyPos(1): Print Kirby$(CURRENT_KIRBY)
'Draw grass Color(0, 255, 0) 'Green color For Y = 20 To 24 For X = 0 To TextCols()
Locate X, Y: Print"'"
Next Next
DrawText() Wend
Lil' less advanced, no structures, no subs/functions, if you still havng problems understanding the code, let me know.
|
|
|
Post by Nicky Peter Hollyoake on Jan 22, 2008 6:38:22 GMT -5
I'll explain a few things that you probaly don't know (because I talk on MSN with yeah so I know what you know & not know).
TextCols - Returns the value of your width (text width). So you know theres for on the default size do yeah? So it would return 40. EXAMPLE:
Print TextCols()
Textrows - is the same, but it returns the value of the height (text height).
Once again EXAMPLE:
Print TextRows()
Should print 25, on default size.
if you wanna change the size of your writing though use the command "ResizeText(50, 30)" and the TextCols(), TextRows() will change depending on the size you put your text (first slot is width in resizetext, second height).
"TextMode(TEXT_BUFFERED)" holds all text printed until its been called by "DrawText()" and then all text will print.
EXAMPLE:
TextMode(TEXT_BUFFERED) Print"Kirby!": DrawText() 'Will print because DrawText has beeen called Print"Charlie!" 'Wont draw because theres no "DrawText()" after it.
Probaly last code is "SetTextScroll(FALSE)" if your put FALSE init, you won't be able go down the screen.
EXAMPLE ...
SetTextScroll(FALSE)
Dim i
For i = 0 To i Printr i Next
But when its true ...
SetTextScroll(TRUE)
Dim i
For i = 0 To i Printr i Next
Tryed to explain things really simple, need help with anything else just ask.
|
|
|
Post by hiiamevil on Jan 23, 2008 7:18:48 GMT -5
thnx nicky ill mess around with this in a second
|
|
|
Post by hiiamevil on Jan 23, 2008 7:26:17 GMT -5
Code: TextMode(TEXT_BUFFERED) Print"Kirby!": DrawText() 'Will print because DrawText has beeen called Print"Charlie!" 'Wont draw because theres no "DrawText()" after it. ------------------------------------------------------------------------------------------------------------------------
it will only print if i have draw text() beside it the first time or every print?
thats my only question right now
|
|
|
Post by Nicky Peter Hollyoake on Jan 23, 2008 8:04:23 GMT -5
Nope because if that was the case, then we'll still have a flickering screen! send it after all the text if you like.
TextMode(TEXT_BUFFERED) Printr"My name is Charlie" Printr"I am creating a game called Kirby" Print"This is Kirby: <( O_O )>" DrawText()
We don't want one coming up at the time,
TextMode(TEXT_BUFFERED) Printr"My name is Charlie": DrawText() Printr"I am creating a game called Kirby": DrawText() Print"This is Kirby: <( O_O )>": DrawText()
Because basicailly if you wanted to do that you might aswell do this,
Printr"My name is Charlie" Printr"I am creating a game called Kirby" Print"This is Kirby: <( O_O )>"
Heres another example:
TextMode(TEXT_BUFFERED) 'Holds in all text
While TRUE 'is our infinity loop CLS 'Clears the screen
'Our text thats been holded in by the "TextMode(TEXT_BUFFERED)" Locate 0, 0: Print"Lifes = 2" Locate 0, 1: Print"Score = 1000" Locate 7, 24: Print"<!>"
DrawText() 'The command that releases the text from the "TextMode(TEXT_BUFFERED)" Wend 'returns us to while
Hope that explains things good for you.
|
|
|
Post by hiiamevil on Jan 23, 2008 22:57:07 GMT -5
i see, im going to add a enemy with arrays
|
|