so i am making a game about placing blocks and building and i have made it so that you can walk up blocks like stairs, how ever i cant figure out how to make them come back down. I have tried lots of things it either glitches them through the floor or makes the camera go weird. Here is the game in action
The Builder Game
And here is the source code:
Rem Project: Builder Game
Rem Created: Friday, February 14, 2014
Rem Created by Thomas Montano
Rem Art By Sam Honcoop
Rem ***** Main Source File *****
hide mouse
load image "media/Dirt.bmp", 2
load image "media/Hammer.bmp", 1
load image "media/Character right.bmp", 3
load image "media/Character left.bmp", 4
load image "media/Stone.bmp", 5
load image "media/Wood.bmp", 6
global selectedblock as byte = 0
global stringselectedblock as string = "Delete"
global xpos as integer = 128
global ypos as integer = 1920
global zpos as integer = 0
global direction as byte = 3
global objects as integer = 2
global camz as integer = 300
global blocknumber as byte = 8
Sync on
sync rate 70
make camera 1
make matrix 1,2048,2048,32,32
prepare matrix texture 1,2,1,1
position matrix 1,0,0,0
update matrix 1
XRotate Camera 1, 65
//set the initial camera position
set camera to follow 1, xpos, 150, ypos, 0, 100, camz, 1, 0
//a test command for placing blocks
make object box 1, 64, 1, 64
position object 1, xpos, zpos, ypos
set object 1, 1, 1, 1
make object cube 11, 64
position object 11, 160, 32, 288
texture object 11, 2
make object cube 2, 64
position object 2, 224, 32, 224
texture object 2, 6
make object cube 3, 64
position object 3, 224, 96, 160
texture object 3, 6
make object cube 4, 64
position object 4, 224, 160, 96
texture object 4, 6
make object cube 5, 64
position object 5, 224, 192, 32
texture object 5, 6
make object cube 6, 64
position object 6, 288, 192, 32
texture object 6, 6
make object cube 7, 64
position object 7, 160, 192, 32
texture object 7, 6
make object cube 8, 64
position object 8, 32, 32, 32
texture object 8, 5
make object cube 9, 64
position object 9, 92, 32, 32
texture object 9, 5
make object cube 10, 64
position object 10, 156, 32, 32
texture object 10, 5
do
if keystate(19) = 1 then zpos = 0
if keystate(19) = 1 then camz = 300
//update camera
set camera to follow 1, xpos, 150, ypos, 0, 100, camz, 1, 0
//test for collisions
for objects = 1 to 7
if object collision(1,object)
text 5, 55, "Hit"
inc zpos, 64
inc camz, 64
position object 1, xpos, zpos, ypos
set camera to follow 1, xpos, 100, ypos, 0, 100, camz, 1, 0
endif
next objects
texture object 1, direction
position object 1, xpos, zpos, ypos
if object collision(1,2) > 0 and zpos > 1 then dec zpos, 64
sync
// displaying the location of the character
text 5, 5, str$(object position x(1))
text 5, 15, str$(object position y(1))
text 5, 25, str$(object position z(1))
text 5, 35, "Mouse x: " + str$(mousex())
text 5, 45, "Mouse y: " + str$(mousey())
// creation and movement of the character
// determine what key was pressed and orient the sprite accordingly
if keystate(17) = 1
inc ypos, 3 //up
endif
if keystate(32) = 1
inc xpos, 3
direction = 3
endif //right
if keystate(30) = 1 //left
dec xpos, 3
direction = 4
endif
if keystate(31) = 1
dec ypos, 3 //down
endif
//make the limits of the world so the player cant walk off
if ypos < 32 then inc ypos, 3
if ypos > 2070 then dec ypos, 3
if xpos < -15 then inc xpos, 3
if xpos > 2048 then dec xpos, 3
// the text and inventory system
if scancode() = 2 then selectedblock = 0
if scancode() = 3 then selectedblock = 1
if scancode() = 4 then selectedblock = 2
text 1, 10, " " + stringselectedblock
if selectedblock = 0
stringselectedblock = "Delete"
endif
if selectedblock = 1
stringselectedblock = "Stone Brick"
endif
if selectedblock = 2
stringselectedblock = "Dirt"
endif
//make the block appear near the mouse
if selectedblock = 2 then paste image 2, mousex(), mousey()
if selectedblock = 1 then paste image 5, mousex(), mousey()
// make the hammer not stick around when a different item is selected
if selectedblock = 0
sprite 2, mousex(), mousey(), 1
else
sprite 2, -400, -400, 1
endif
//allow block placing
loop
end
If you could show me how to make gravity that would be great. Also if there is anything i could do to make the code better that would be nice. And if yo have any tips about how to make blocks place able then i would love to hear that too. Thanks for the help as always guys!
-FishCube-