My first REAL project a 2D Adventure game

Blitz3D Forums/Blitz3D Beginners Area/My first REAL project a 2D Adventure game

Ok, i know i'm missing somthing... I'm gonna atempt to make my first game, for those who have helped me with my first ever project, a Breakout clone. That showed me the basics of programming operators (+,-,>,<,=>,=, Ect..) functions, some types... and the "IF THEN" and stuff like that... now i want to make somthing everyone can enjoy, (stupid me for making a game that can only fit my huge screen).

I want to use this thread if i get stuck and cant get out.

now, i have 2 things i'v been pondering:

How to make a room, i'm sure you guys have played SNES games like zelda ect, now my guess is the map is a backround image, and you some how set collisions up with parts of the map.

lets say i have a map that looks like this:

!@#$!@#$!@#$
#@$---------!@#
!@#----------!@#
!@##------@!@#
!@#!@#!@@#@

the odd signs are walls, the "-"'s are the walking space this whole thing is a image, how would i make it so i cant go through areas?

second of all... Real time rotation... lets say i have a image i want it to face DOWN,UP,LEFT, and RIGHT when the right keys are pressed.

E.G: If you press the right arrowkey [->] the image faces right, and goes right then when you let off it stays in the right possition until a nother key is pressed...


HOW?!!?

i tried a few things... no avail...

When a key is pressed, use imagescollide function between your bloke at the position he would move to and the background image. You may have two images for the background- one with all the screen images, including background and platforms, and one with just the platforms and collidable stuff that you use only for collision test.

Ok... what about the directing of the image or bloke..? i guess i could make 4 images and rotate them differently then pick what one to draw based on the key press, but is there a easer way to make 4 images? could i do a loop that creates 4 images? but then how would i name them differently... its all so confusing...

Ok, i'm having a problem with a "Toggle switch" basicly if you hit R then run mode is on... and if its on and you hit it, run mode is off... heres the code:

If KeyHit(R) And runmode=1 Then
runmode=2
Else If KeyHit(R) And runmode=2 Then
runmode=1
End If



sounds right.. what am i doing wrong... feel free to laugh ... but then tell me what i'm doing wrong...

edit, and i did make a veriable called R=19, it works because i can turn it on, but not off..

You should use a boolean for your runmode var, it would be more logical, and much easier.
if keyhit(R) then runMode = not runMode


This would work but the way i have it set up now, the runmode is how many pixels the image moves...

If keydownblahblah
Player_y=Player_y+runmode

If KeyHit(R) And runmode=1 Then
runmode=2
Else If KeyHit(R) And runmode=2 Then
runmode=1
End If


it works because i can turn it on, but not off..



EDITED FOR CLARITY: It fails because the second Keyhit(), if it happens, is asking "Has R been hit since the last check?". The player would have to press R twice EXCEEDINGLY quickly for that to ever be true. Truncate it to one check:

If KeyHit(R)
    if runmode=1
       runmode=2
    else
       runmode=1
    endif
End If


Which can be further reduced to...
If KeyHit(R) then runmode=3-runmode


Ok, that works perfectly, thanks. now back to a bigger problem...

i made a image called playeru that is a sqaure with a line poking out of it (for seeing the direction) now i did copy image 4 times naming the other 3 images playerd,playerr,playerl and rotated them accordingly, and made them draw depending on what key is pressed, how do i make it remember what the last key was pressed and keep drawing that image untill a nother key is pressed in that case draw the new image?

Edit mabye some code may help:

mainpage.bb
AppTitle "2D project","Your leaving? not so fast..."

Graphics 800,600,16,2
SetBuffer BackBuffer()

Global playerx=380,playery=280,runmode=1
Global playeru,playerr,playerd,playerl

Const UPARR=200, DOWNARR=208, LEFTARR=203, RIGHTARR=205, R=19


playeru=CreateImage(20,40)

SetBuffer ImageBuffer(playeru)
Rect 0,20,20,20,1
Line 10,20,10,0
SetBuffer BackBuffer()

playerd=CopyImage(playeru)
RotateImage playerd,180
playerl=CopyImage(playeru)
RotateImage playerl,270
playerr=CopyImage(playeru)
RotateImage playerr,90

While Not KeyHit(1)
Cls


keycontrols()

If runmode=2
Text 0,0,"RunMode = ON"
Else
Text 0,0,"RunMode = OFF"
End If

Delay 5
Flip
Wend
End

Include "functions.bb"


functions.bb
Function keycontrols()
If KeyHit(R)
    if runmode=1
       runmode=2
    else
       runmode=1
    EndIf
End If
If KeyDown(UPARR) And playery>0 Then
playery=playery-runmode
DrawImage playeru,playerx,playery
End If
If KeyDown(DOWNARR) And playery<560 Then
playery=playery+runmode
DrawImage playerd,playerx+20,playery+60
End If
If KeyDown(RIGHTARR) And playerx<780 Then
playerx=playerx+runmode
DrawImage playerr,playerx+40,playery+20
End If
If KeyDown(LEFTARR) And playerx>0 Then
playerx=playerx-runmode
DrawImage playerl,playerx-19,playery+40
End If
End Function



Excuse the messy code, didnt have time to comment it or tab it..

Simply designate a variable for keeping track of the player's direction then draw the player based on that rather than only drawing 'im when a key is pressed. You really need to think about separating your logic from your rendering/drawing.

Awsome, i'm gonna do a bit of code cleaning (Tabbing comenting and reducing the need of lines)


I'll let you know if i run into a brick wall again.

Thanks for all your help guys