Posted: Sat Jun 12, 2004 11:10 pm Post subject: Problems with jumping in my platform game.
This is my mario-style game.
Why is it that:
A) When you hold up and down at the same time you sort of fly.
B) When you jump from high enough and hold up, you double jump in mid-air sometimes.
Any help would be appreciated.
code:
setscreen ("offscreenonly")
var x, vx, y, vy, grav := 0.0
var chars : array char of boolean
var xsize, ysize := 10
var jump := true
var cheats : string
x := xsize + 20
y := ysize + 100
vx := 0
grav := 0.3
loop
delay (20)
cls
Input.KeyDown (chars)
if chars (KEY_CTRL) then
get cheats
if cheats = "nogravity" and grav ~= 0.07 then
grav := 0.07
else
grav := 0.3
end if
end if
if chars (KEY_UP_ARROW) and not jump then
vy := 5
jump := true
elsif chars (KEY_UP_ARROW) and chars (KEY_DOWN_ARROW) then
ysize := 7
elsif chars (KEY_DOWN_ARROW) and jump then
vy := -5
ysize := 8
elsif chars (KEY_DOWN_ARROW) and not jump then
ysize := 5
else
ysize := 10
end if
if chars (KEY_LEFT_ARROW) then
vx := -3
elsif chars (KEY_RIGHT_ARROW) then
vx := 3
else
vx := 0
end if
if jump then
y += vy
vy -= grav
else
vy := 0
end if
ysize += round (vy / 2)
x += vx
for i : 0 .. 5
drawfilloval (round (x), round (y), xsize - i, ysize - i, RGB.AddColor (i / 5, i / 5, 0))
end for
drawfilloval (round (x) - 3 + round (vx), round (y) + 3 + round (vy), 2, 2, 7)
drawfilloval (round (x) + 3 + round (vx), round (y) + 3 + round (vy), 2, 2, 7)
drawdot (round (x) - 3 + round (vx), round (y) + 3 + round (vy), 0)
drawdot (round (x) + 3 + round (vx), round (y) + 3 + round (vy), 0)
drawline (round (x) - 2 + round (vx), round (y) - 3 + round (vy), round (x) + 2 + round (vx), round (y) - 3 + round (vy), 7)
if whatdotcolor (round (x), round (y) + ysize + 1) ~= 0 then
y -= 1
end if
if y - ysize <= 100 or whatdotcolor (round (x), round (y) - ysize - 1) ~= 0 then
jump := false
elsif whatdotcolor (round (x), round (y) - ysize - 1) = 0 then
jump := true
end if
if whatdotcolor (round (x), round (y) + ysize + 1) ~= 0 then
vy := -0.5
elsif ~chars (KEY_DOWN_ARROW) and whatdotcolor (round (x), round (y) - ysize - 1) ~= 0 then
y += 1
end if
if chars (KEY_LEFT_ARROW) and whatdotcolor (round (x) - xsize - 1, round (y)) ~= 0 then
x -= vx
end if
if chars (KEY_RIGHT_ARROW) and whatdotcolor (round (x) + xsize + 1, round (y)) ~= 0 then
x -= vx
end if
View.Update
end loop
Sponsor Sponsor
Cervantes
Posted: Sun Jun 13, 2004 8:23 am Post subject: (No subject)
oh my, I love your character! You are truly an artist!!
but, unfortunately, in your attempt to give him a mouth, you created the problem that led you here.
When your character jumps and you hit down, he looks down. ie, his eyes and mouth move under his body kinda. nice looking, but it screws things up. because then when the program asks,
code:
if y - ysize <= 100 or whatdotcolor (round (x), round (y) - ysize - 1) ~= 0 then
the whatdotcolour says is checking right where that pesky mouth is and it says "no, it's not = 0" and it therefore goes into that if statement, and does this:
code:
jump := false
Now that jump is false, both of these conditions:
code:
if chars (KEY_UP_ARROW) and not jump then
can be satisfied, since jump was made false.
your second problem is the same. after a while, his mouth and eyes aim downwards if he's in the air long enough. hitting down just accelerates how long it takes before his eyes and eyebrow are underneath him.
So, basically, he's jumping off of his own mouth.
to fix it, comment out this line
now he has no eyebrows, and his eyes aren't a problem because no part of them is exactly in the centre of his body (when using whatdotcolour, you check at x, the exact middle of his body. the eyes are on either side). I guess the easiest way to fix this is chaning the colours around a bit. Make his mouth a dark brown or something and incorporate that into the whatdotcolour collision.
now its time for my question(s):
in an if statement when you're comparing two things, what does ~= do? I guess its like not but im not sure. I'm ~ sure?
and what's with the ~ before chars in this if statement:
code:
elsif ~chars (KEY_DOWN_ARROW) and whatdotcolor (round (x), round (y) - ysize - 1) ~= 0 then
Cheers
SuperGenius
Posted: Sun Jun 13, 2004 9:10 am Post subject: (No subject)
I like the complex animation of the character, in only a few lines. good job on that.
mynameisbob
Posted: Sun Jun 13, 2004 10:02 am Post subject: (No subject)
Cervantes, I think your talking about his mouth.
Cervantes
Posted: Sun Jun 13, 2004 12:44 pm Post subject: (No subject)
erg, i tihnk that you will have to do the same thing with the eyes, because if you are moving left or right one part of the eyes will have the same x value as the centre of the character..
in other words, you can do the double jump if you are moving left or right.
GlobeTrotter
Posted: Sun Jun 13, 2004 1:25 pm Post subject: (No subject)
Thanks. I figured it out from there. I simply changed all ~= 0 to = 7 basically. Then I changed the color of my mouth and eyes so that they are different from the bricks. As for ~=, it is the same as not =.
Here is an updated example.
code:
setscreen ("graphics:650;510,nobuttonbar,nocursor,noecho,offscreenonly")
var x, vx, y, vy, grav := 0.0
var chars : array char of boolean
var xsize, ysize := 10
var exsize, eysize : int
var win, jump, dying, dead := true
var cheats, temp : string
var enemies, ecount := 5
var ecolor : array 1 .. enemies of int
var ex : array 1 .. enemies of real
var ey : array 1 .. enemies of real
var evy, evx : array 1 .. enemies of real
var ejump, edead : array 1 .. enemies of boolean
var mx, my, mb : int
var mlocate := false
var bgcolor, brickcol, lavacol, doorcol : int
procedure InitRoom1
brickcol := 7
doorcol := 4
lavacol := 12
bgcolor := 51
exsize := 8
eysize := 6
colorback (bgcolor)
%Enemies' starting positions
ex (1) := 218
ex (2) := 317
ex (3) := 508
ex (4) := 45
ex (5) := 120
ey (1) := 429
ey (2) := 298
ey (3) := 129
ey (4) := 135
ey (5) := 433
ecount := 5
x := xsize + 20 %Player's starting position
y := ysize + 100 %Player's starting position
for i : 1 .. enemies %Initialize enemie's stuff
edead (i) := false
ejump (i) := false
evy (i) := 0
if i mod 2 = 0 then
ecolor (i) := 1
evx (i) := 1.5
else
ecolor (i) := 0
evx (i) := 1.1
end if
end for
end InitRoom1
procedure DrawRoom1
drawfillbox (648, 97, -29, -22, brickcol)
drawfilloval (277, 97, 107, -19, lavacol)
drawfillbox (128, 139, 168, 122, brickcol)
drawfillbox (186, 165, 218, 146, brickcol)
drawfillbox (243, 192, 270, 176, brickcol)
drawfillbox (354, 161, 382, 140, brickcol)
drawfillbox (398, 194, 437, 173, brickcol)
drawfillbox (455, 236, 530, 216, brickcol)
drawfillbox (545, 275, 605, 255, brickcol)
drawfillbox (399, 110, 383, 89, brickcol)
drawfillbox (172, 112, 151, 84, brickcol)
drawfillbox (519, 311, 437, 296, brickcol)
drawfillbox (387, 276, 200, 263, brickcol)
drawfillbox (387, 290, 373, 276, brickcol)
drawfillbox (209, 293, 199, 270, brickcol)
drawfilloval (289, 274, -17, -4, lavacol)
drawfilloval (237, 276, -14, -2, lavacol)
drawfilloval (346, 275, -13, -2, lavacol)
drawfillbox (154, 316, 116, 305, brickcol)
drawfillbox (56, 345, 98, 331, brickcol)
drawfillbox (16, 384, 60, 366, brickcol)
drawfillbox (76, 413, 252, 401, brickcol)
drawfillbox (252, 432, 235, 401, brickcol)
drawfillbox (89, 433, 76, 402, brickcol)
drawfillbox (153, 369, 211, 355, brickcol)
drawfilloval (180, 368, 21, -6, lavacol)
drawfillbox (159, 429, 168, 411, brickcol)
drawfillbox (193, 428, 206, 409, brickcol)
drawfillbox (295, 420, 339, 403, brickcol)
drawfillbox (373, 418, 408, 401, brickcol)
drawfillbox (428, 440, 459, 426, brickcol)
drawfillbox (470, 456, 499, 442, brickcol)
drawfillbox (506, 477, 545, 463, brickcol)
drawfillbox (572, 478, 654, 460, brickcol)
drawfillbox (626, 478, 656, 526, doorcol)
drawfilloval (633, 496, 2, 2, yellow)
drawfillbox (169, 421, 192, 388, bgcolor)
drawfillbox (187, 409, 195, 379, bgcolor)
drawfillbox (199, 376, 158, 391, bgcolor)
drawfillbox (634, 96, 649, 463, brickcol)
drawfillbox (12, 95, -6, 527, brickcol)
end DrawRoom1
loop
delay (20)
cls
Input.KeyDown (chars)
if chars ('p') then
loop
exit when hasch
locatexy (maxx div 2, maxy div 2)
end loop
end if
if chars (KEY_CTRL) then
get cheats
if cheats = "gravity" then
get grav
end if
if cheats = "locate" then
mlocate := true
end if
if cheats = "locatexy" then
get x, y
end if
if cheats = "killall" then
for i : 1 .. enemies
edead (i) := true
ecount -= 1
end for
end if
if cheats = "color" then
get temp
if temp = "background" then
get bgcolor
elsif temp = "brick" then
get brickcol
elsif temp = "door" then
get doorcol
elsif temp = "lava" then
get lavacol
end if
end if
end if
if mlocate then
mousewhere (mx, my, mb)
if mb = 1 then
x := mx
y := my
end if
end if
if chars (KEY_UP_ARROW) and not jump then
vy := 5
jump := true
elsif chars (KEY_UP_ARROW) and chars (KEY_DOWN_ARROW) then
ysize := 7
elsif chars (KEY_DOWN_ARROW) and jump then
vy := -5
ysize := 8
elsif chars (KEY_DOWN_ARROW) and not jump then
ysize := 5
else
ysize := 10
end if
if chars (KEY_LEFT_ARROW) then
vx := -3
elsif chars (KEY_RIGHT_ARROW) then
vx := 3
else
vx := 0
end if
if jump then
y += vy
vy -= grav
else
vy := 0
end if
if vy < -9 then
dying := true
end if
ysize += round (vy / 2)
x += vx
%ENEMY STUFF
for i : 1 .. enemies
if not edead (i) then
ex (i) += evx (i)
if ejump (i) then
ey (i) += evy (i)
evy (i) -= grav
else
evy (i) := 0
end if
end if
end for
DrawRoom1
for i : 1 .. enemies
if not edead (i) then
for k : 1 .. 5
drawfilloval (round (ex (i)), round (ey (i)), exsize - k, eysize - k, RGB.AddColor (k / 5 * ecolor (i), k / 5, k / 5 * ecolor (i)))
end for
drawfilloval (round (ex (i) + (evx (i)) * 3), round (ey (i)), 1, 1, 7)
drawline (round (ex (i) + (evx (i)) * -6), round (ey (i)) - 1, round (ex (i) + (evx (i)) * -9), round (ey (i)) - 1, 7)
end if
end for
for i : 0 .. 5
drawfilloval (round (x), round (y), xsize - i, ysize - i, RGB.AddColor (i / 5, i / 5, 0))
end for
drawfilloval (round (x) - 3 + round (vx), round (y) + 3 + round (vy), 2, 2, 1)
drawfilloval (round (x) + 3 + round (vx), round (y) + 3 + round (vy), 2, 2, 1)
drawdot (round (x) - 3 + round (vx), round (y) + 3 + round (vy), 0)
drawdot (round (x) + 3 + round (vx), round (y) + 3 + round (vy), 0)
drawline (round (x) - 2 + round (vx), round (y) - 3 + round (vy), round (x) + 2 + round (vx), round (y) - 3 + round (vy), 4)
if whatdotcolor (round (x), round (y) + ysize + 1) = brickcol then
y -= 1
end if
if y - ysize <= 100 or whatdotcolor (round (x), round (y) - ysize - 1) = brickcol then
jump := false
elsif whatdotcolor (round (x), round (y) - ysize - 1) = bgcolor then
jump := true
end if
if whatdotcolor (round (x), round (y) + ysize + 1) = brickcol then
vy := -0.5
elsif ~chars (KEY_DOWN_ARROW) and whatdotcolor (round (x), round (y) - ysize - 1) = brickcol then
y += 1
end if
if chars (KEY_LEFT_ARROW) and whatdotcolor (round (x) - xsize - 1, round (y)) = brickcol then
x -= vx
end if
if chars (KEY_RIGHT_ARROW) and whatdotcolor (round (x) + xsize + 1, round (y)) = brickcol then
x -= vx
end if
if whatdotcolor (round (x), round (y) - ysize - 1) = brickcol and dying then
dead := true
end if
if whatdotcolor (round (x), round (y) - ysize - 2) = lavacol then
dead := true
end if
%ENEMY STUFF
for i : 1 .. enemies
if not edead (i) then
if whatdotcolor (round (ex (i)), round (ey (i)) - eysize - 1) = bgcolor then
ejump (i) := true
else
ejump (i) := false
end if
if whatdotcolor (round (ex (i)) - exsize - 1, round (ey (i))) = brickcol or whatdotcolor (round (ex (i)) + 9, round (ey (i))) = brickcol then
evx (i) *= -1
end if
if sqrt ((ex (i) - x) ** 2 + (ey (i) - y) ** 2) < ysize + exsize + 1 and vy < -1.3 then
edead (i) := true
ecount -= 1
vy := 4
elsif sqrt ((ex (i) - x) ** 2 + (ey (i) - y) ** 2) < ysize + exsize + 1 and vy > -1.3 then
dead := true
end if
end if
end for
if ecount = 0 and whatdotcolor (round (x) + xsize + 4, round (y)) = doorcol then
win := true
elsif whatdotcolor (round (x) + xsize + 4, round (y)) = 4 and ecount ~= 0 then
for i : 1 .. 10
cls
colorback (RGB.AddColor (i / 10, i / 10, 0))
delay (100)
View.Update
end for
colorback (0)
x := xsize + 20 %Player's starting position
y := ysize + 100 %Player's starting position
end if
View.Update
exit when dead or win
end loop
if dead then
for i : 1 .. 10
cls
colorback (RGB.AddColor (i / 10, 0, 0))
delay (100)
View.Update
end for
else
for i : 1 .. 10
cls
colorback (RGB.AddColor (0, i / 10, 0))
delay (100)
View.Update
end for
end if
colorback (0)
exit when not dead
end loop
SuperGenius
Posted: Sun Jun 13, 2004 2:43 pm Post subject: (No subject)
Wow i like what you did with it.
GlobeTrotter
Posted: Sun Jun 13, 2004 9:20 pm Post subject: (No subject)
I added another level, and I have another question.
How would it be possible to stop my guy from bouncing? I may keep him bouncing since he is a ball, but for gameplay's sake, I'd like to see how the game plays without the bouncing. I didn't program the bounce intentionally, so I don't know how to stop it. Help please.
code:
setscreen ("graphics:650;510,nobuttonbar,nocursor,noecho,offscreenonly")
var x, vx, y, vy, grav := 0.0
var chars : array char of boolean
var xsize, ysize := 10
var exsize, eysize : int
var win, jump, dying, dead := true
var cheats, temp : string
var enemies, ecount := 5
var ecolor : array 1 .. enemies of int
var ex : array 1 .. enemies of real
var ey : array 1 .. enemies of real
var evy, evx : array 1 .. enemies of real
var ejump, edead : array 1 .. enemies of boolean
var mx, my, mb : int
var mlocate, nofalldie := false
var bgcolor, brickcol, lavacol, doorcol : int
const dyingspeed := 10
procedure InitRoom1
brickcol := 7
doorcol := 4
lavacol := 12
bgcolor := 51
exsize := 8
eysize := 6
colorback (bgcolor)
%Enemies' starting positions
ex (1) := 218
ex (2) := 317
ex (3) := 508
ex (4) := 45
ex (5) := 120
ey (1) := 429
ey (2) := 298
ey (3) := 129
ey (4) := 135
ey (5) := 433
ecount := 5
x := xsize + 20 %Player's starting position
y := ysize + 100 %Player's starting position
for i : 1 .. enemies %Initialize enemie's stuff
edead (i) := false
ejump (i) := false
evy (i) := 0
if i mod 2 = 0 then
ecolor (i) := 1
evx (i) := 1.5
else
ecolor (i) := 0
evx (i) := 1.1
end if
end for
end InitRoom1
procedure InitRoom2
brickcol := 7
doorcol := 4
lavacol := 12
bgcolor := 51
exsize := 8
eysize := 6
colorback (bgcolor)
%Enemies' starting positions
ex (1) := 406
ex (2) := 575
ex (3) := 125
ex (4) := 212
ex (5) := 254
ey (1) := 353
ey (2) := 388
ey (3) := 433
ey (4) := 246
ey (5) := 171
ecount := 5
x := xsize + 20 %Player's starting position
y := ysize + 100 %Player's starting position
for i : 1 .. enemies %Initialize enemie's stuff
edead (i) := false
ejump (i) := false
evy (i) := 0
if i mod 2 = 0 then
ecolor (i) := 2
evx (i) := 1.5
else
ecolor (i) := 0
evx (i) := 1.1
end if
end for
end InitRoom2
procedure DrawRoom1
drawfillbox (648, 97, -29, -22, brickcol)
drawfilloval (277, 97, 107, -19, lavacol)
drawfillbox (128, 139, 168, 122, brickcol)
drawfillbox (186, 165, 218, 146, brickcol)
drawfillbox (243, 192, 270, 176, brickcol)
drawfillbox (354, 161, 382, 140, brickcol)
drawfillbox (398, 194, 437, 173, brickcol)
drawfillbox (455, 236, 530, 216, brickcol)
drawfillbox (545, 275, 605, 255, brickcol)
drawfillbox (399, 110, 383, 89, brickcol)
drawfillbox (172, 112, 151, 84, brickcol)
drawfillbox (519, 311, 437, 296, brickcol)
drawfillbox (387, 276, 200, 263, brickcol)
drawfillbox (387, 290, 373, 276, brickcol)
drawfillbox (209, 293, 199, 270, brickcol)
drawfilloval (289, 274, -17, -4, lavacol)
drawfilloval (237, 276, -14, -2, lavacol)
drawfilloval (346, 275, -13, -2, lavacol)
drawfillbox (154, 316, 116, 305, brickcol)
drawfillbox (56, 345, 98, 331, brickcol)
drawfillbox (16, 384, 60, 366, brickcol)
drawfillbox (76, 413, 252, 401, brickcol)
drawfillbox (252, 432, 235, 401, brickcol)
drawfillbox (89, 433, 76, 402, brickcol)
drawfillbox (153, 369, 211, 355, brickcol)
drawfilloval (180, 368, 21, -6, lavacol)
drawfillbox (159, 429, 168, 411, brickcol)
drawfillbox (193, 428, 206, 409, brickcol)
drawfillbox (295, 420, 339, 403, brickcol)
drawfillbox (373, 418, 408, 401, brickcol)
drawfillbox (428, 440, 459, 426, brickcol)
drawfillbox (470, 456, 499, 442, brickcol)
drawfillbox (506, 477, 545, 463, brickcol)
drawfillbox (572, 478, 654, 460, brickcol)
drawfillbox (626, 478, 656, 526, doorcol)
drawfilloval (633, 496, 2, 2, yellow)
drawfillbox (169, 421, 192, 388, bgcolor)
drawfillbox (187, 409, 195, 379, bgcolor)
drawfillbox (199, 376, 158, 391, bgcolor)
drawfillbox (634, 96, 649, 463, brickcol)
drawfillbox (12, 95, -6, 527, brickcol)
end DrawRoom1
loop
delay (20)
cls
Input.KeyDown (chars)
if chars ('p') then
loop
exit when hasch
locatexy (maxx div 2, maxy div 2)
end loop
end if
if chars (KEY_CTRL) then
get cheats
if cheats = "gravity" or cheats = "grav" then
get grav
end if
if cheats = "locate" then
if ~mlocate then
mlocate := true
else
mlocate := false
end if
end if
if cheats = "locatexy" then
get x, y
end if
if cheats = "killall" then
for i : 1 .. enemies
edead (i) := true
ecount -= 1
end for
end if
if cheats = "nextlevel" then
for i : 1 .. enemies
edead (i) := true
ecount -= 1
end for
drawfilloval (round (x) + xsize + 4, round (y), 4, 4, doorcol)
end if
if cheats = "color" then
get temp
if temp = "background" then
get bgcolor
colorback (bgcolor)
cls
elsif temp = "brick" then
get brickcol
elsif temp = "door" then
get doorcol
elsif temp = "lava" then
get lavacol
end if
end if
if cheats = "nofalldie" then
if ~nofalldie then
nofalldie := true
else
nofalldie := false
end if
end if
if cheats = "restart" then
if level = 1 then
InitRoom1
elsif level = 2 then
InitRoom2
end if
end if
end if
if mlocate then
mousewhere (mx, my, mb)
if mb = 1 then
x := mx
y := my
vy := 0
end if
end if
if chars (KEY_UP_ARROW) and not jump then
vy := 5
jump := true
elsif chars (KEY_UP_ARROW) and chars (KEY_DOWN_ARROW) then
ysize := 7
elsif chars (KEY_DOWN_ARROW) and jump then
vy := -5
ysize := 8
elsif chars (KEY_DOWN_ARROW) and not jump then
ysize := 5
else
ysize := 10
end if
if chars (KEY_LEFT_ARROW) then
vx := -3
elsif chars (KEY_RIGHT_ARROW) then
vx := 3
else
vx := 0
end if
if jump then
y += vy
vy -= grav
else
vy := 0
end if
if ~nofalldie and vy < -dyingspeed then
dying := true
end if
ysize += round (vy / 2)
x += vx
%ENEMY STUFF
for i : 1 .. enemies
if not edead (i) then
ex (i) += evx (i)
if ejump (i) then
ey (i) += evy (i)
evy (i) -= grav
else
evy (i) := 0
end if
end if
end for
if level = 1 then
DrawRoom1
elsif level = 2 then
DrawRoom2
end if
for i : 1 .. enemies
if not edead (i) then
for k : 1 .. 5
drawfilloval (round (ex (i)), round (ey (i)), exsize - k, eysize - k, RGB.AddColor (k / 5 * ecolor (i), k / 5, k / 5 * ecolor (i)))
end for
drawfilloval (round (ex (i) + (evx (i)) * 3), round (ey (i)), 1, 1, 7)
drawline (round (ex (i) + (evx (i)) * -6), round (ey (i)) - 2, round (ex (i) + (evx (i)) * -9), round (ey (i)) - 2, 7)
end if
end for
for i : 0 .. 5
drawfilloval (round (x), round (y), xsize - i, ysize - i, RGB.AddColor (i / 5, i / 5, 0))
end for
drawfilloval (round (x) - 3 + round (vx), round (y) + 3 + round (vy), 2, 2, 1)
drawfilloval (round (x) + 3 + round (vx), round (y) + 3 + round (vy), 2, 2, 1)
drawdot (round (x) - 3 + round (vx), round (y) + 3 + round (vy), 0)
drawdot (round (x) + 3 + round (vx), round (y) + 3 + round (vy), 0)
drawline (round (x) - 2 + round (vx), round (y) - 3 + round (vy), round (x) + 2 + round (vx), round (y) - 3 + round (vy), 4)
if whatdotcolor (round (x), round (y) + ysize + 1) = brickcol and whatdotcolor (round (x), round (y) - ysize - 1) ~= brickcol then
y -= 1
elsif whatdotcolor (round (x), round (y) + ysize + 1) = brickcol and whatdotcolor (round (x), round (y) - ysize - 1) = brickcol then
y += 1
end if
if whatdotcolor (round (x), round (y) - ysize - 1) = brickcol then
jump := false
elsif whatdotcolor (round (x), round (y) - ysize - 1) = bgcolor then
jump := true
end if
if whatdotcolor (round (x), round (y) + ysize + 1) = brickcol then
vy := -0.5
elsif ~chars (KEY_DOWN_ARROW) and whatdotcolor (round (x), round (y) - ysize - 1) = brickcol then
y += 2
end if
if chars (KEY_LEFT_ARROW) and whatdotcolor (round (x) - xsize - 1, round (y)) = brickcol then
x -= vx
end if
if chars (KEY_RIGHT_ARROW) and whatdotcolor (round (x) + xsize + 1, round (y)) = brickcol then
x -= vx
end if
if whatdotcolor (round (x), round (y) - ysize - 1) ~= bgcolor and dying then
dead := true
end if
if whatdotcolor (round (x), round (y) - ysize - 1) = lavacol then
dead := true
end if
%ENEMY STUFF
for i : 1 .. enemies
if not edead (i) then
if whatdotcolor (round (ex (i)), round (ey (i)) - eysize - 1) = bgcolor then
ejump (i) := true
else
ejump (i) := false
end if
if whatdotcolor (round (ex (i)) - exsize - 1, round (ey (i))) = brickcol or whatdotcolor (round (ex (i)) + 9, round (ey (i))) = brickcol then
evx (i) *= -1
end if
if sqrt ((ex (i) - x) ** 2 + (ey (i) - y) ** 2) < ysize + exsize + 1 and vy < -1.3 then
edead (i) := true
ecount -= 1
vy := 4
elsif sqrt ((ex (i) - x) ** 2 + (ey (i) - y) ** 2) < ysize + exsize + 1 and vy > -1.3 then
dead := true
end if
end if
end for
if ecount = 0 and whatdotcolor (round (x) + xsize + 4, round (y)) = doorcol then
win := true
elsif whatdotcolor (round (x) + xsize + 4, round (y)) = 4 and ecount ~= 0 then
for i : 1 .. 10
cls
colorback (RGB.AddColor (i / 10, i / 10, 0))
delay (100)
View.Update
end for
colorback (bgcolor)
x := xsize + 20 %Player's starting position
y := ysize + 100 %Player's starting position
end if
View.Update
exit when dead or win
end loop
if dead then
for i : 1 .. 10
cls
colorback (RGB.AddColor (i / 10, 0, 0))
delay (100)
View.Update
end for
else
for i : 1 .. 10
cls
colorback (RGB.AddColor (0, i / 10, 0))
delay (100)
View.Update
end for
end if
colorback (0)
exit when not dead
end loop
end for
Sponsor Sponsor
mynameisbob
Posted: Sun Jun 13, 2004 10:32 pm Post subject: (No subject)
they both look like the same level...
i think ive found a bug in ur game. Usually when the player falls from a high place he dies, but if you hold down while falling he doesnt die.
GlobeTrotter
Posted: Sun Jun 13, 2004 11:11 pm Post subject: (No subject)
I will try and fix the bug. It is caused by: When the player hits down and he's in mid-air it sets his vertical velocity to a certain amount (less than the max speed before he is killed). The only thing I can think of is so that when you press down in mod-air, you can can only press it once per jump.
As for them both being the same level, you have to beat the first level to get to the second.
Cervantes
Posted: Mon Jun 14, 2004 8:25 am Post subject: (No subject)
this game has lots of potential! keep working on it.
to stop him from bouncing, try commenting out these lines:
code:
elsif ~chars (KEY_DOWN_ARROW) and whatdotcolor (round (x), round (y) - ysize - 1) = brickcol then
y += 2
hope that helps
beard0
Posted: Mon Jun 14, 2004 10:19 am Post subject: (No subject)
Great game! I was messing around with your latest version, and found one little bug: When I was falling quickly, I was able to fall through some of a smaller piece of "ground" I'd suggest that you put your whatdotcolor testing in a for loop to check all the pixels between the bottom of your character, and the pixel at which his bottom would next be at the current velocity. But other than that, it looks pretty good to me.
GlobeTrotter
Posted: Mon Jun 14, 2004 3:12 pm Post subject: (No subject)
Cervantes wrote:
this game has lots of potential! keep working on it.
to stop him from bouncing, try commenting out these lines:
code:
elsif ~chars (KEY_DOWN_ARROW) and whatdotcolor (round (x), round (y) - ysize - 1) = brickcol then
y += 2
hope that helps
That doesn't really help, since that is what I use so that when his downward velocity is greater than 1 and he hits the brick in the middle of it, he moves to the top of it. When I uncommented that, and jumped from a relatively high height he went right to the middle of the brick and got stuck.
beard0
Posted: Tue Jun 15, 2004 9:39 am Post subject: (No subject)
GlobeTrotter:
Try re-commenting that section, and applying my for loop whatdotcolor testing, so that as he falls, you can stop him from getting to the middle of the ground that way. (if there's ground somwhere within the space between him and where he should be in the next frame, just set his y value to be on the ground.
Once you have this all set up, you'll have to make a level editor !
Good Luck!
GlobeTrotter
Posted: Thu Jun 17, 2004 6:44 pm Post subject: (No subject)
I managed to stop the bounce. I also added some other features:
-cooler background
-coins
-no longer go through blocks
Here it is. You need to kill all the people to progress to the next level. Try and collect coins too.
code:
setscreen ("graphics:650;530,nobuttonbar,nocursor,noecho,offscreenonly")
var gmaxx, gmaxy : int
gmaxx := 650
gmaxy := 510
var x, vx, y, vy, grav := 0.0
var chars : array char of boolean
var xsize, ysize := 10
var exsize, eysize : int
var win, jump, dying, dead := true
var cheats, temp : string
var enemies, ecount := 5
var ecolor : array 1 .. enemies of int
var ex : array 1 .. enemies of real
var ey : array 1 .. enemies of real
var evy, evx : array 1 .. enemies of real
var ejump, edead : array 1 .. enemies of boolean
var coins := 10
var cx : array 1 .. coins of int
var cy : array 1 .. coins of int
var cdead : array 1 .. coins of boolean
var coincount : int := 0
var mx, my, mb : int
var mlocate, nofalldie, cheatlevel := false
var bgcolor, brickcol, lavacol, doorcol : int
var starx, stary : array 1 .. 100 of int
var starsize : int
var timer : int := 1
const dyingspeed := 10
procedure InitRoom1
timer := 1
grav := 0.3
brickcol := 2
doorcol := 4
lavacol := 12
bgcolor := 7
exsize := 8
eysize := 6
cheatlevel := false
colorback (bgcolor)
%Enemies' starting positions
ex (1) := 218
ex (2) := 317
ex (3) := 508
ex (4) := 45
ex (5) := 120
ey (1) := 429
ey (2) := 298
ey (3) := 129
ey (4) := 135
ey (5) := 433
%Coin Positions
cx (1) := 525
cy (1) := 490
cx (2) := 483
cy (2) := 472
cx (3) := 207
cy (3) := 385
cx (4) := 442
cy (4) := 457
cx (5) := 23
cy (5) := 198
cx (6) := 83
cy (6) := 482
cx (7) := 619
cy (7) := 115
cx (8) := 255
cy (8) := 213
cx (9) := 199
cy (9) := 185
cx (10) := 146
cy (10) := 162
for i : 1 .. coins
cdead (i) := false
end for
ecount := 5
x := xsize + 20 %Player's starting position
y := ysize + 100 %Player's starting position
for i : 1 .. enemies %Initialize enemie's stuff
edead (i) := false
ejump (i) := false
evy (i) := 0
if i mod 2 = 0 then
ecolor (i) := 1
evx (i) := 1.5
else
ecolor (i) := 0
evx (i) := 1.1
end if
end for
for i : 1 .. 100
starx (i) := Rand.Int (0, gmaxx)
stary (i) := Rand.Int (0, gmaxy)
end for
end InitRoom1
procedure InitRoom2
timer := 0
grav := 0.3
brickcol := 15
doorcol := 4
lavacol := 112
bgcolor := 7
exsize := 8
eysize := 6
cheatlevel := false
colorback (bgcolor)
%Enemies' starting positions
ex (1) := 406
ex (2) := 575
ex (3) := 125
ex (4) := 212
ex (5) := 254
ey (1) := 353
ey (2) := 388
ey (3) := 433
ey (4) := 246
ey (5) := 171
ecount := 5
%Coin Positions
cx (1) := 166
cy (1) := 87
cx (2) := 114
cy (2) := 144
cx (3) := 163
cy (3) := 195
cx (4) := 202
cy (4) := 197
cx (5) := 561
cy (5) := 282
cx (6) := 424
cy (6) := 304
cx (7) := 144
cy (7) := 292
cx (8) := 167
cy (8) := 405
cx (9) := 305
cy (9) := 404
cx (10) := 541
cy (10) := 327
for i : 1 .. coins
cdead (i) := false
end for
x := xsize + 20 %Player's starting position
y := ysize + 100 %Player's starting position
for i : 1 .. enemies %Initialize enemie's stuff
edead (i) := false
ejump (i) := false
evy (i) := 0
if i mod 2 = 0 then
ecolor (i) := 2
evx (i) := 1.5
else
ecolor (i) := 0
evx (i) := 1.1
end if
end for
for i : 1 .. 100
starx (i) := Rand.Int (0, gmaxx)
stary (i) := Rand.Int (0, gmaxy)
end for
end InitRoom2
procedure DrawRoom1
if timer < 3000 then
timer += 1
end if
bgcolor := RGB.AddColor (timer / 10000, timer / 10000, timer / 5000)
brickcol := RGB.AddColor (timer / 10000, 0.3 + timer / 10000, timer / 10000)
colorback (bgcolor)
cls
for i : 1 .. 100
randint (starsize, 0, 1)
drawfilloval (starx (i) - timer div 110, stary (i) - timer div 60, starsize, starsize, RGB.AddColor (stary (i) / 500, stary (i) / 500, stary (i) / 500))
end for
for i : 1 .. 25
drawfilloval (75 - timer div 50, gmaxy - 100 - timer div 50, 50 - i div 2, 50 - i div 2, RGB.AddColor (i / 25, i / 25, i / 35))
end for
for i : 1 .. coins
if ~cdead (i) then
drawfilloval (cx (i), cy (i), timer mod 5, 5, yellow)
end if
end for
drawfillbox (648, 97, -29, -22, brickcol)
drawfilloval (277, 97, 107, -19, lavacol)
drawfillbox (128, 139, 168, 122, brickcol)
drawfillbox (186, 165, 218, 146, brickcol)
drawfillbox (243, 192, 270, 176, brickcol)
%drawfillbox (354, 161, 382, 140, brickcol)
drawfillbox (398, 194, 437, 173, brickcol)
drawfillbox (455, 236, 530, 216, brickcol)
drawfillbox (545, 275, 605, 255, brickcol)
drawfillbox (399, 110, 383, 89, brickcol)
drawfillbox (172, 112, 151, 84, brickcol)
drawfillbox (519, 311, 437, 296, brickcol)
drawfillbox (387, 276, 200, 263, brickcol)
drawfillbox (387, 290, 373, 276, brickcol)
drawfillbox (209, 293, 199, 270, brickcol)
drawfilloval (289, 274, -17, -4, lavacol)
drawfilloval (237, 276, -14, -2, lavacol)
drawfilloval (346, 275, -13, -2, lavacol)
drawfillbox (154, 316, 116, 305, brickcol)
drawfillbox (56, 345, 98, 331, brickcol)
drawfillbox (16, 384, 60, 366, brickcol)
drawfillbox (76, 413, 252, 401, brickcol)
drawfillbox (252, 432, 235, 401, brickcol)
drawfillbox (89, 433, 76, 402, brickcol)
drawfillbox (153, 369, 211, 355, brickcol)
drawfilloval (180, 368, 21, -6, lavacol)
drawfillbox (159, 429, 168, 411, brickcol)
drawfillbox (193, 428, 206, 409, brickcol)
drawfillbox (295, 420, 339, 403, brickcol)
drawfillbox (373, 418, 408, 401, brickcol)
drawfillbox (428, 440, 459, 426, brickcol)
drawfillbox (470, 456, 499, 442, brickcol)
drawfillbox (506, 477, 545, 463, brickcol)
drawfillbox (572, 478, 654, 460, brickcol)
drawfillbox (626, 478, 656, 526, doorcol)
drawfilloval (633, 496, 2, 2, yellow)
drawfillbox (169, 421, 192, 388, bgcolor)
drawfillbox (187, 409, 195, 379, bgcolor)
drawfillbox (199, 376, 158, 391, bgcolor)
drawfillbox (634, 96, 649, 463, brickcol)
drawfillbox (12, 95, -6, 527, brickcol)
end DrawRoom1
loop
delay (15)
cls
Input.KeyDown (chars)
if chars ('p') then
loop
exit when hasch
locatexy (gmaxx div 2, gmaxy div 2)
end loop
end if
if chars (KEY_CTRL) then
get cheats
if cheats = "gravity" or cheats = "grav" then
get grav
end if
if cheats = "locate" then
if ~mlocate then
mlocate := true
else
mlocate := false
end if
end if
if cheats = "locatexy" then
get x, y
end if
if cheats = "killall" then
for i : 1 .. enemies
edead (i) := true
ecount -= 1
end for
end if
if cheats = "nextlevel" then
cheatlevel := true
end if
if cheats = "color" then
get temp
if temp = "background" then
get bgcolor
colorback (bgcolor)
cls
elsif temp = "brick" then
get brickcol
elsif temp = "door" then
get doorcol
elsif temp = "lava" then
get lavacol
end if
end if
if cheats = "nofalldie" then
if ~nofalldie then
nofalldie := true
else
nofalldie := false
end if
end if
if cheats = "restart" then
if level = 1 then
InitRoom1
elsif level = 2 then
InitRoom2
end if
end if
end if
if chars (KEY_UP_ARROW) and not jump then
vy := 5
jump := true
elsif chars (KEY_UP_ARROW) and chars (KEY_DOWN_ARROW) then
ysize := 7
if vy > 0 then
vy *= -0.5
end if
elsif chars (KEY_DOWN_ARROW) and jump then
if vy > 0 then
vy *= -1
end if
ysize := 6
elsif chars (KEY_DOWN_ARROW) and not jump then
ysize := 6
else
ysize := 10
end if
if chars (KEY_LEFT_ARROW) then
vx := -3
elsif chars (KEY_RIGHT_ARROW) then
vx := 3
else
vx := 0
end if
if jump then
y += vy
vy -= grav
else
vy := 0
end if
if ~nofalldie and vy < -dyingspeed then
dying := true
end if
ysize += round (vy / 2)
x += vx
%ENEMY STUFF
for i : 1 .. enemies
if not edead (i) then
ex (i) += evx (i)
if ejump (i) then
ey (i) += evy (i)
evy (i) -= grav
else
evy (i) := 0
end if
end if
end for
if level = 1 then
DrawRoom1
elsif level = 2 then
DrawRoom2
end if
drawfillbox (0, gmaxy, maxx, maxy, brickcol)
if coincount < 10 then
drawfilloval (maxx - 15, gmaxy + 8, timer mod 4, 5, red)
locatexy (maxx - 5, gmaxy + 8)
color (0)
put coincount
else
drawfilloval (maxx - 35, gmaxy + 8, timer mod 4, 5, red)
locatexy (maxx - 15, gmaxy + 8)
color (0)
put coincount
end if
for i : 1 .. enemies
if not edead (i) then
for k : 1 .. 5
drawfilloval (round (ex (i)), round (ey (i)), exsize - k, eysize - k, RGB.AddColor (k / 5 * ecolor (i), k / 5, k / 5 * ecolor (i)))
end for
drawfilloval (round (ex (i) + (evx (i)) * 3), round (ey (i)), 1, 1, 7)
drawline (round (ex (i) + (evx (i)) * -6), round (ey (i)) - 2, round (ex (i) + (evx (i)) * -9), round (ey (i)) - 2, 7)
end if
end for
for i : 0 .. 5
drawfilloval (round (x), round (y), xsize - i, ysize - i, RGB.AddColor (i / 5, i / 5, 0))
end for
drawfilloval (round (x) - 3 + round (vx), round (y) + 3 + round (vy), 2, 2, 1)
drawfilloval (round (x) + 3 + round (vx), round (y) + 3 + round (vy), 2, 2, 1)
drawdot (round (x) - 3 + round (vx), round (y) + 3 + round (vy), 0)
drawdot (round (x) + 3 + round (vx), round (y) + 3 + round (vy), 0)
drawline (round (x) - 2 + round (vx), round (y) - 3 + round (vy), round (x) + 2 + round (vx), round (y) - 3 + round (vy), 4)
if whatdotcolor (round (x), round (y) + ysize + 1) = brickcol and whatdotcolor (round (x), round (y) - ysize - 1) ~= brickcol then
y -= 1
elsif whatdotcolor (round (x), round (y) + ysize + 1) = brickcol and whatdotcolor (round (x), round (y) - ysize - 1) = brickcol then
y += 1
end if
if whatdotcolor (round (x), round (y + vy - ysize - 1)) = brickcol then
jump := false
elsif whatdotcolor (round (x), round (y + vy - ysize - 1)) = bgcolor then
jump := true
end if
if whatdotcolor (round (x), round (y + vy + ysize + 1)) = brickcol then
vy := -0.5
elsif ~chars (KEY_DOWN_ARROW) and whatdotcolor (round (x), round (y) - ysize - 1) = brickcol then
y += 2
end if
if chars (KEY_LEFT_ARROW) and whatdotcolor (round (x) - xsize - 1, round (y)) = brickcol then
x -= vx
end if
if chars (KEY_RIGHT_ARROW) and whatdotcolor (round (x) + xsize + 1, round (y)) = brickcol then
x -= vx
end if
if whatdotcolor (round (x), round (y) - ysize - 1) ~= bgcolor and dying then
dead := true
end if
if whatdotcolor (round (x), round (y) - ysize - 1) = lavacol then
dead := true
end if
%ENEMY STUFF
for i : 1 .. enemies
if not edead (i) then
if whatdotcolor (round (ex (i)), round (ey (i)) - eysize - 1) = bgcolor then
ejump (i) := true
else
ejump (i) := false
end if
if whatdotcolor (round (ex (i)) - exsize - 1, round (ey (i))) = brickcol or whatdotcolor (round (ex (i)) + 9, round (ey (i))) = brickcol then
evx (i) *= -1
end if
if sqrt ((ex (i) - x) ** 2 + (ey (i) - y) ** 2) < ysize + exsize + 1 and vy < -1.3 then
edead (i) := true
ecount -= 1
if chars (KEY_UP_ARROW) then
vy := 7
else
vy := 4
end if
elsif sqrt ((ex (i) - x) ** 2 + (ey (i) - y) ** 2) < ysize + exsize + 1 and vy > -1.3 then
dead := true
end if
end if
end for
%COIN STUFF
for i : 1 .. coins
if whatdotcolor (cx (i), cy (i) - 6) ~= bgcolor and ~cdead (i) then
cdead (i) := true
coincount += 1
end if
end for
if ecount = 0 and whatdotcolor (round (x) + xsize + 4, round (y)) = doorcol then
win := true
elsif whatdotcolor (round (x) + xsize + 4, round (y)) = 4 and ecount ~= 0 then
for i : 1 .. 10
cls
colorback (RGB.AddColor (i / 10, i / 10, 0))
delay (100)
View.Update
end for
colorback (bgcolor)
x := xsize + 20 %Player's starting position
y := ysize + 100 %Player's starting position
end if
if mlocate then
mousewhere (mx, my, mb)
if mb = 1 then
x := mx
y := my
vy := 0
color (0)
locate (1, 1)
put "(", mx, ",", my, ")"
end if
end if
View.Update
exit when dead or win or cheatlevel
end loop
if dead then
for i : 1 .. 10
cls
colorback (RGB.AddColor (i / 10, 0, 0))
delay (100)
View.Update
end for
else
for i : 1 .. 10
cls
colorback (RGB.AddColor (0, i / 10, 0))
delay (100)
View.Update
end for
end if
colorback (0)
exit when not dead
end loop
end for