Hi guys,
I am programming a direct copy of the arcade game \"Stacker\"
http://www.youtube.com/watch?v=mG4TM4L81eU, but am coming up against a few problems.
I have the blocks moving, leveling up when you press spacebar, and some other simple things like that, but I am having a really hard time checking to make sure the current blocks are over the old blocks.
I don\'t think the code is that complex, but I just can\'t get my head around it.
If someone could point me in the right direction, that would be fantastic. The code is VERY messy, and completely hacked together. I\'ve been bashing my head against this one problem for a day now, and it\'s not getting any easier. Also, I am on a rather tight deadline for this, so if anyone can help, I\'d really appreciate it sooner rather than later
The code is attached at the bottom here, and should run fine in DBPro. I am using IanM\'s Alarm functions, and someone else\'s key-press function. I can\'t remember who wrote it though.
I can\'t offer any money payment, but maybe if you need some concept art done, I could help? I do a lot of environmental stuff, so if anyone needs a concept image, and can help, maybe we can sort something out.
Cheers,
Greenlig
Rem Project: Stacker
Rem Created: Friday, September 17, 2010
Rem ***** Main Source File *****
//set up the screen properties
SET DISPLAY MODE 320, 480, 32
sync on
sync rate 60
//Variable Declarations
#constant MAX_ALARM 64
gridX as integer
startX = Screen Width() + 45
startY = Screen Height()
bricks_playing = 4
dir_change as boolean
dir_change = 0
mover as integer
levels as integer
first_run as boolean
first_run = 1
limit as integer
limit = 7
olds as integer
olds = 0
loss_count as integer
loss_count = 0
win_count as integer
win_count = 0
old_limit as integer
old_limit = 100
play_speed = 500
play as integer
play = 1
//Type Declarations
Type brick
xPos as integer
yPos as integer
flag as boolean
playing as boolean
level as integer
startX as integer
endtype
//Array Declarations
dim brick(bricks_playing) as brick
brick(0).xPos = startX - 45
brick(0).yPos = startY - 45
brick(0).flag = 0
brick(0).playing = 1
brick(0).startX = startX - 45
brick(1).xPos = startX
brick(1).yPos = startY - 45
brick(1).flag = 0
brick(1).playing = 1
brick(1).startX = startX
brick(2).xPos = startX + 45
brick(2).yPos = startY - 45
brick(2).flag = 0
brick(2).playing = 1
brick(2).startX = startX + 45
brick(3).xPos = startX + 90
brick(3).yPos = startY - 45
brick(3).flag = 0
brick(3).playing = 1
brick(3).startX = startX + 90
dim old_pos(bricks_playing) as brick
for i = 0 to bricks_playing
old_pos(i).xPos = - 90
old_pos(i).playing = 1
next i
dim all_olds(old_limit) as brick
for i = 1 to old_limit
all_olds(i).xPos = -90
next i
dim missed_bricks(100) as brick
dim check(bricks_playing) as brick
dim key(250) : dim oldkey(250)
//Variable Calculations
gridX = Screen Width() / 7
bricks_playing = bricks_playing - 1
//Draw some stuff
Draw_Bricks()
CreateAlarm(1, play_speed, 1)
CreateAlarm(2, 200, 1)
//------------------------------------------------------------------Do Loop--------------------------------------------------------//
Do
cls
for a = 1 to 250
if key(a) = 1 then oldkey(a) = 1
if keystate(a) = 1 and oldkey(a) = 0 : key(a) = 1 : else : key(a) = 0 : endif
if keystate(a) = 0 then oldkey(a) = 0
next a
if first_run and mover = 4
first_run = 0
mover = 1
endif
//--------------------------------------compute movement
if Alarm(1)
if mover < limit
inc mover
endif
if mover > limit - 1
mover = 1
if dir_change = 0
dir_change = 1
else
dir_change = 0
endif
endif
if dir_change = 0
for i = 0 to bricks_playing
brick(i).xPos = brick(i).xPos - 45
next i
else
limit = 8
for i = 0 to bricks_playing
brick(i).xPos = brick(i).xPos + 45
next i
endif
for i = 0 to bricks_playing
// if old_pos(0).level < brick(0).level - 1 or brick(1).level - 1 or brick(2).level - 1 or brick(3).level - 1 then old_pos(0).xPos = -90
// if old_pos(1).level < brick(0).level - 1 or brick(1).level - 1 or brick(2).level - 1 or brick(3).level - 1 then old_pos(1).xPos = -90
// if old_pos(2).level < brick(0).level - 1 or brick(1).level - 1 or brick(2).level - 1 or brick(3).level - 1 then old_pos(2).xPos = -90
// if old_pos(3).level < brick(0).level - 1 or brick(1).level - 1 or brick(2).level - 1 or brick(3).level - 1 then old_pos(3).xPos = -90
//if levels > 1
if brick(i).playing = 1
if old_pos(0).level < brick(i).level
old_pos(0).flag = 0
else
old_pos(0).flag = 1
endif
if old_pos(1).level < brick(i).level
old_pos(1).flag = 0
else
old_pos(1).flag = 1
endif
if old_pos(2).level < brick(i).level
old_pos(2).flag = 0
else
old_pos(2).flag = 1
endif
if old_pos(3).level < brick(i).level
old_pos(3).flag = 0
else
old_pos(3).flag = 1
endif
endif
//endif
next i
if levels > 0
// for i = 0 to bricks_playing
// if ff = 0
// if old_pos(i).flag = 1
// ff = 1
// stop = i
// sf = 0
// else
// ff = 0
// endif
// endif
// next i
//
// for i = stop to bricks_playing
// if ff = 1 and sf = 0
// if old_pos(i).flag = 0
// sf = 1
// final = i
// ff = 0
// else
// sf = 0
// endif
// endif
// next i
endif
if brick(0).playing = 1
if (brick(0).xPos > old_pos(0).xPos - 45) and (brick(0).xPos < old_pos(0).xPos + 45)
// if old_pos(0).flag = 1
brick(0).flag = 1
else
// if old_pos(0).flag = 0
// brick(0).flag = 0
brick(0).flag = 0
// endif
endif
if (brick(0).xPos > old_pos(1).xPos - 45) and (brick(0).xPos < old_pos(1).xPos + 45)
brick(0).flag = 1
else
brick(0).flag = 0
endif
//
// if old_pos(2).flag = 1
// if (brick(0).xPos > old_pos(2).xPos - 45) and (brick(0).xPos < old_pos(2).xPos + 45)
// brick(0).flag = 1
// endif
// endif
//
// if old_pos(3).flag = 1
// if (brick(0).xPos > old_pos(3).xPos - 45) and (brick(0).xPos < old_pos(3).xPos + 45)
// brick(0).flag = 1
// endif
// endif
endif
// for i = 0 to bricks_playing
// if brick(1).playing = 1
// if old_pos(i).flag = 1
// if (brick(1).xPos > old_pos(i).xPos - 45) and (brick(1).xPos < old_pos(i).xPos + 45)
// brick(1).flag = 1
// else
// brick(1).flag = 0
// endif
// endif
// endif
// next i
//
// for i = 0 to bricks_playing
// if brick(2).playing = 1
// if old_pos(i).flag = 1
// if (brick(2).xPos > old_pos(i).xPos - 45) and (brick(2).xPos < old_pos(i).xPos + 45)
// brick(2).flag = 1
// else
// brick(2).flag = 0
// endif
// endif
// endif
// next i
//
// for i = 0 to bricks_playing
// if brick(3).playing = 1
// if old_pos(i).flag = 1
// if (brick(3).xPos > old_pos(i).xPos - 45) and (brick(3).xPos < old_pos(i).xPos + 45)
// brick(3).flag = 1
// else
// brick(3).flag = 0
// endif
// endif
// endif
// next i
DeleteAlarm(1)
CreateAlarm(1, play_speed, 1)
endif
//-------------------------------------------------------controls--------------------------------------------//
if key(57) = 1
if levels > 0
for i = 0 to bricks_playing
if brick(i).playing = 1 and brick(i).flag = 0
inc loss_count
brick(i).playing = 0
endif
next i
endif
//save old brick location
for i = 0 to bricks_playing
if brick(i).playing = 1
// if old_pos(i).playing = 1
old_pos(i).xPos = brick(i).xPos
old_pos(i).yPos = brick(i).yPos
// old_pos(i).playing = brick(i).playing
old_pos(i).level = levels
brick(i).level = levels
// endif
endif
next i
//save old bricks to the all_olds array
for i = 0 to bricks_playing
all_olds(olds).xPos = old_pos(i).xPos
all_olds(olds).yPos = old_pos(i).yPos
//if olds <= bricks_playing
inc olds
// endif
next i
// for i = 0 to bricks_playing
//
// if old_pos(i).level < levels
//
// old_pos(i).playing = 0
// endif
//
// next i
// for i = 0 to bricks_playing
//
// if old_pos(i).level < levels - 1
// old_pos(i).xPos = -90
// endif
//
// next i
inc levels
//move bricks up a level and restart them off screen
for i = 0 to bricks_playing
// if brick(i).playing = 1
brick(i).yPos = brick(i).yPos - 45
brick(i).xPos = brick(i).startX
//old_pos(i).level = levels
// endif
next i
mover = 1
first_run = 1
dir_change = 0
stop = 0
final = 0
if play_speed > 150
play_speed = play_speed - 50
endif
if levels > 6
for i = 0 to 100
all_olds(i).yPos = all_olds(i).yPos + 45
next i
for i = 0 to bricks_playing
brick(i).yPos = brick(i).yPos + 45
old_pos(i).yPos = old_pos(i).yPos + 45
next i
endif
endif
text 60,10,\"num \" + str$(num)
text 60,30,\"level \" + str$(levels)
text 60,50,\"final \" + str$(final)
//text 60,80,\"Flag 4 \" + str$(brick(3).flag)
//------------------------------------------------------------------Draw Bricks---------------------------------------------------------//
Draw_Bricks()
//draw grid (function not working??)
line startX-1, 0, startX-1, startY
line startX, startY-1, 0, startY-1
for i = startX to 0 step -gridX
for j = startY to 0 step -gridX
line i, startY, i, 0
line startX, j, 0, j
next i
next j
for i = 0 to olds
if levels > 0
ink RGB(0,200,200),RGB(255,255,255)
BOX all_olds(i).xPos, all_olds(i).yPos, all_olds(i).xPos + 45, all_olds(i).yPos + 45
ink RGB(255,255,255),RGB(0,0,0)
endif
next i
for i = 0 to bricks_playing
if levels > 0
ink RGB(0,0,255),RGB(255,255,255)
BOX old_pos(i).xPos, old_pos(i).yPos, old_pos(i).xPos + 45, old_pos(i).yPos + 5
ink RGB(255,255,255),RGB(0,0,0)
endif
next i
//--------------------------//
for i = 0 to bricks_playing
//if brick(i).playing = 1
ink RGB(255,0,0),RGB(255,255,255)
text old_pos(i).xPos + (45*0.5), old_pos(i).yPos + (45*0.5),str$(old_pos(i).flag)
//text all_olds(i).xPos + (45*0.5), all_olds(i).yPos + (45*0.5),str$(all_olds(i).flag)
text brick(i).xPos + (45*0.5), brick(i).yPos + (45*0.5),str$(brick(i).flag)
ink RGB(255,255,255),RGB(0,0,0)
text brick(i).xPos + (45*0.5), brick(i).yPos - (45),str$(brick(i).flag)
//endif
next i
sync
loop
//----------------------------------------------------FUNCTIONS--------------------------------------------------------//
function Draw_Bricks()
for i = 0 to array count (brick(0))
if brick(i).playing = 1
if brick(i).flag = 1
BOX brick(i).xPos, brick(i).yPos, brick(i).xPos+45, brick(i).yPos+45,RGB(0,192,0),RGB(0,192,0),RGB(0,192,0),RGB(0,192,0)
else
BOX brick(i).xPos, brick(i).yPos, brick(i).xPos+45, brick(i).yPos+45
endif
endif
next i
endfunction
function Draw_Old()
for i = 0 to levels
BOX all_olds(i).xPos, all_olds(i).yPos, all_olds(i).xPos + 45, all_olds(i).yPos + 45
next i
endfunction
function Draw_All_Olds()
for i = 0 to levels
BOX all_olds(i).xPos, all_olds(i).yPos, all_olds(i).xPos + 45, all_olds(i).yPos + 45
next i
endfunction
function Draw_Grid()
line startX-1, 0, startX-1, startY
line startX, startY-1, 0, startY-1
for i = startX to 0 step -gridX
for j = startY to 0 step -gridX
line i, startY, i, 0
line startX, j, 0, j
next i
next j
endfunction
remstart
AVAILABLE FUNCTIONS*********************************************************************
CreateAlarm()
Creates and initialises an alarm
Alarm()
Tests the alarm to see if it has \'gone off\'
DeleteAlarm()
Deletes the specified alarm
****************************************************************************************
remend
type alarm_t
Active as integer ` Set to 1 if the timer is active
Respawn as integer ` Set to 0 if no respawn, or the timer increment if there is a respawn
Time as integer ` Contains the time of the next alarm
endtype
dim Store_Alarm(MAX_ALARM) as alarm_t
global AlarmCreated as integer
function CreateAlarm(AlarmNo as integer, TimeIncrement as integer, Respawn as integer)
if AlarmCreated = 0
undim Store_Alarm()
global dim Store_Alarm(MAX_ALARM) as alarm_t
AlarmCreated = 1
endif
if AlarmNo < 1 or AlarmNo > MAX_ALARM then exitfunction 0
if Store_Alarm( AlarmNo ).Active <> 0 then exitfunction 0
Store_Alarm( AlarmNo ).Active = 1
Store_Alarm( AlarmNo ).Time = timer() + TimeIncrement
if Respawn = 0
Store_Alarm( AlarmNo ).Respawn = 0
else
Store_Alarm( AlarmNo ).Respawn = TimeIncrement
endif
endfunction 1
function Alarm(AlarmNo as integer)
if AlarmNo < 1 or AlarmNo > MAX_ALARM then exitfunction 0
if Store_Alarm( AlarmNo ).Active = 0 then exitfunction 0
if Store_Alarm( AlarmNo ).Time > timer() then exitfunction 0
if Store_Alarm( AlarmNo ).Respawn = 0
Store_Alarm( AlarmNo ).Active = 0
else
Store_Alarm( AlarmNo ).Time = Store_Alarm( AlarmNo).Time + Store_Alarm( AlarmNo ).Respawn
endif
endfunction 1
function DeleteAlarm(AlarmNo as integer)
Store_Alarm( AlarmNo ).Active = 0
endfunction
Your signature has been erased by a mod as it is far too big.