PAPIJUMP almost done, scrolling help!
Author |
Message |
B-Man 31
|
Posted: Mon Jan 25, 2010 5:28 pm Post subject: PAPIJUMP almost done, scrolling help! |
|
|
So im making PapiJump a popular game for the iPhone and i need help getting the scrolling to work better so that he cant go of the top. Here is a browser playable version so you can see the difference.
Here is my Code:
Turing: |
%PAPIJUMP IN OOP
%BEN SPITZER
%SETSCREEN
var window := Window.Open ("offscreenonly,graphics:250,500,position:center,center,nobuttonbar,title:PapiJump by Ben Spitzer")
%PLATFORM CLASS
class platform
export all
%PLATFORM TYPE
type aPlatform :
record
x, y, clr : int
end record
%VARIABLES
var pform : aPlatform
var lastpform : int
var Platform := Pic.FileNew ("Platform.bmp")
var Background := Pic.FileNew ("Background.bmp")
var bgx, bgy : int := 0
%CONSTANTS
const maxpform := 20
const minwidth := 25
const pformwidth := Pic.Width (Platform )
pform.y := 0
pform.x := 100
proc drawplatform (X, Y : int)
pform.x := X % RIGHT SIDE
pform.y := Y % HEIGHT
Pic.Draw (Platform, pform.x, pform.y, picMerge)
end drawplatform
proc drawbackground
Pic.Draw (Background, bgx, bgy, picCopy)
Pic.Draw (Background, bgx, bgy + Pic.Height (Background ), picCopy)
Pic.Draw (Background, bgx, bgy + (Pic.Height (Background ) * 2), picCopy)
end drawbackground
proc movebackground (y, ysp : real, menu : boolean)
if not menu then
if y > maxy div 2 and ysp > 0 then
bgy - = (ysp div 3)
end if
else
bgy - = 10
end if
if bgy < - Pic.Height (Background ) then
bgy := 0
end if
end movebackground
%GENERATES PLATFORM ACCORDING TO THE LAST ONE MADE
proc generate (upperpformy, upperpformx, maxh, maxw : int)
pform.y + = Rand.Int (upperpformy + minwidth, upperpformy + maxh )
pform.x := Rand.Int (upperpformx - maxw, upperpformx + maxw )
if pform.x < 0 then
pform.x := maxx - 50
elsif pform.x > maxx - 50 then
pform.x := 0
end if
end generate
%CHECKS WHICH PLATFORM IS THE LAST ONE
proc getlast (i : int)
if i not= 1 then
lastpform := i - 1
else
lastpform := maxpform
end if
end getlast
%MOVES THE PLATFOrMS DOWN
proc move (y, jump : real)
if round (y ) > maxy div 2 and jump > 0 then
pform.y - = round (jump )
end if
end move
%RESET PLATFORMS
proc resetplatform
pform.y := 0
pform.x := 100
end resetplatform
end platform
%SET UP PLATFORM VARIABLE
var aplatform : flexible array 1 .. 1 of ^platform
new platform, aplatform (upper (aplatform ))
%PLAYER CLASS
class player
import Input, aplatform, platform
export all
%PLAYER TYPE
type aPlayer :
record
x, y, xsp, ysp : real
end record
%VARIABLES
var user : aPlayer
var done : boolean := false
var chars : array char of boolean
var Mr_Papi := Pic.FileNew ("Mr.Papi.bmp")
%CONSTANTS
const gravity := 1
const radius := Pic.Height (Mr_Papi ) div 2
const movespeed := 0. 5
const jumpspeed := 15
const maxvelocity := - 14
const maxjump := 75
const maxwidth := 80
user.xsp := 0
user.ysp := 0
user.x := maxx div 2
user.y := 50
proc move
Input.KeyDown (chars )
if chars (KEY_LEFT_ARROW) then %MOVER LEFT
user.xsp + = -movespeed
elsif chars (KEY_RIGHT_ARROW) then %MOVE RIGHT
user.xsp + = movespeed
end if
%MOVE THE PLAYER
if user.ysp > maxvelocity then
user.ysp - = gravity
end if
user.x + = user.xsp
user.y + = user.ysp
end move
proc draw
Pic.Draw (Mr_Papi, round (user.x ) - radius, round (user.y ) - radius, picMerge)
end draw
%DETECTS IF MR.PAPI HITS PLATFORM
fcn pformDetect (x, y, temp, py, px, px2, ysp : real) : boolean
result y + temp <= py + radius and y + temp >= py + radius - 5 and x + radius >= px and x - radius <= px2 and ysp < 0
end pformDetect
proc detect
%SET BOUNDERIES
%RIGHT AND LEFT
if user.x - radius > maxx then
user.x := -radius
elsif user.x + radius < 0 then
user.x := maxx + radius
end if
%IF YOU LOST
if user.y + radius <= 0 then
done := true
end if
%PLATFROM DETECTION
for o : 1 .. aplatform (upper (aplatform )) -> maxpform
for decreasing i : - 1 .. - round (abs (user.ysp ))
if pformDetect (user.x, user.y, i, aplatform (o ) -> pform.y + Pic.Height (aplatform (o ) -> Platform ), aplatform (o ) -> pform.x,
aplatform (o ) -> pform.x + aplatform (o ) -> pformwidth, user.ysp ) then
user.ysp := jumpspeed
end if
end for
end for
end detect
%RESET PLAYER
proc playerreset
done := false
user.xsp := 0
user.ysp := 0
user.x := maxx div 2
user.y := 50
end playerreset
end player
%SET UP PLAYER VARIABLE
var aplayer : ^player
new player, aplayer
%SCORE CLASS
class score
import player, aplayer, platform, aplatform, Mouse
export all
var playerscore : int := 0
var fontx : int := 0
var file : int
var timescore : int
var x, y, button : int
var menu : boolean
var time1 := Time.Elapsed
var highscore, hiscore : string := "0"
var scorestr : string
var font := Font.New ("ariel:15")
%DISPLAYS SCORE
proc drawscore
scorestr := "Score: " + intstr (playerscore )
fontx := (maxx div 2) - (length (scorestr ) * 5)
Font.Draw (scorestr, fontx, 425, font, white)
end drawscore
%COUNTS SCORE
proc getscore
if aplayer -> user.y > maxy div 2 then
timescore := (Time.Elapsed - time1 ) div 1000
playerscore + = timescore
end if
end getscore
%CHECKS TO SEE IF HIGH SCORE AND SAVES IT
proc gethighscore
open : file, "Highscore", read
read : file, highscore
close : file
if playerscore > strint (highscore ) then
open : file, "Highscore", write
highscore := intstr (playerscore )
write : file, highscore
close : file
end if
end gethighscore
%DRAWS MENU
proc drawmenu
open : file, "Highscore", read
read : file, highscore
close : file
hiscore := "Hi-Score: " + highscore
menu := true
loop
aplatform (1) -> drawbackground
aplatform (1) -> movebackground (aplayer -> user.y, aplayer -> user.ysp, menu )
Font.Draw (hiscore, (maxx div 2) - (length (hiscore ) * 5), 300, font, white)
Font.Draw ("Click to Start", 70, 75, font, yellow)
Mouse.Where (x, y, button )
exit when button = 1 and x > 0 and y > 0 and x < maxx and y < maxy
Time.DelaySinceLast (20)
View.Update
end loop
menu := false
end drawmenu
%RESET SCORE
proc scorereset
playerscore := 0
end scorereset
end score
%SET UP SCORE VARIABLE
var ascore : ^score
new score, ascore
class reset
import ascore, score, aplayer, player, aplatform, platform
export all
%CALLS ALL RESET PROCEDURES
proc resetall
aplayer -> playerreset
ascore -> scorereset
for i : 1 .. aplatform (upper (aplatform )) -> maxpform
aplatform (i ) -> resetplatform
end for
end resetall
end reset
%SET UP RESET VARIABLE
var areset : ^reset
new reset, areset
%INITIATE PLATFORMS
for i : 2 .. aplatform (upper (aplatform )) -> maxpform + 1
new aplatform, (upper (aplatform ) + 1)
new platform, aplatform (upper (aplatform ))
aplatform (i ) -> getlast (i )
aplatform (i ) -> generate (aplatform (aplatform (i ) -> lastpform ) -> pform.y, aplatform (aplatform (i ) -> lastpform ) -> pform.x, aplayer -> maxjump, aplayer -> maxwidth )
end for
%PROGRAM
loop
%MENU
ascore -> drawmenu
loop
%BACKGROUND
aplatform (1) -> drawbackground
aplatform (1) -> movebackground (aplayer -> user.y, aplayer -> user.ysp, ascore -> menu )
%PLATFROMS
for i : 1 .. aplatform (upper (aplatform )) -> maxpform
aplatform (i ) -> drawplatform (aplatform (i ) -> pform.x, aplatform (i ) -> pform.y )
aplatform (i ) -> move (aplayer -> user.y, aplayer -> user.ysp )
if aplatform (i ) -> pform.y < 0 then
aplatform (i ) -> getlast (i )
aplatform (i ) -> generate (aplatform (aplatform (i ) -> lastpform ) -> pform.y, aplatform (aplatform (i ) -> lastpform ) -> pform.x, aplayer -> maxjump, aplayer -> maxwidth )
end if
end for
%PLAYER
aplayer -> move
aplayer -> draw
aplayer -> detect
%SCORE
ascore -> getscore
ascore -> drawscore
exit when aplayer -> done
View.Update
cls
Time.DelaySinceLast (30)
end loop
%GET HIGHSCORE
ascore -> gethighscore
%RESETALL
areset -> resetall
for i : 2 .. aplatform (upper (aplatform )) -> maxpform + 1
aplatform (i ) -> getlast (i )
aplatform (i ) -> generate (aplatform (aplatform (i ) -> lastpform ) -> pform.y, aplatform (aplatform (i ) -> lastpform ) -> pform.x, aplayer -> maxjump, aplayer -> maxwidth )
end for
end loop
Window.Close (window )
|
Description: |
This is the Game with Pictures! |
|
Download |
Filename: |
PapiJump.rar |
Filesize: |
8.57 KB |
Downloaded: |
200 Time(s) |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
ProgrammingFun
|
Posted: Mon Jan 25, 2010 9:27 pm Post subject: RE:PAPIJUMP almost done, scrolling help! |
|
|
This might not be of much help but your program is a little too sensitive to the key commands and continues to follow a certain j\key even after the user has let go.
GREAT GAME THOUGH!
|
|
|
|
|
|
B-Man 31
|
Posted: Mon Jan 25, 2010 10:36 pm Post subject: Re: RE:PAPIJUMP almost done, scrolling help! |
|
|
ProgrammingFun @ Mon Jan 25, 2010 9:27 pm wrote: This might not be of much help but your program is a little too sensitive to the key commands and continues to follow a certain j\key even after the user has let go.
GREAT GAME THOUGH!
Thanks, but its supposed to be like that, did you try playing the online version i linked?
|
|
|
|
|
|
ProgrammingFun
|
Posted: Tue Jan 26, 2010 2:10 pm Post subject: Re: RE:PAPIJUMP almost done, scrolling help! |
|
|
B-Man 31 @ Mon Jan 25, 2010 10:36 pm wrote: ProgrammingFun @ Mon Jan 25, 2010 9:27 pm wrote: This might not be of much help but your program is a little too sensitive to the key commands and continues to follow a certain j\key even after the user has let go.
GREAT GAME THOUGH!
Thanks, but its supposed to be like that, did you try playing the online version i linked?
No, but I did play it on iPhone.
|
|
|
|
|
|
B-Man 31
|
Posted: Thu Jan 28, 2010 8:48 pm Post subject: RE:PAPIJUMP almost done, scrolling help! |
|
|
Seriously, no ones gonna help me out!?
|
|
|
|
|
|
TerranceN
|
Posted: Thu Jan 28, 2010 10:07 pm Post subject: RE:PAPIJUMP almost done, scrolling help! |
|
|
You need to move the screen proportionaly to how far the player is offscreen, rather then at a constant rate.
I dont quite understand your screen movement code, but if you find the distance on the y-axis between the top of the screen and the player, when the player is offscreen, and move the screen up that far, your player will always be visible.
I hope that helps.
Also, what is the point of putting this into a class?
Turing: | class reset
import ascore, score, aplayer, player, aplatform, platform
export all
%CALLS ALL RESET PROCEDURES
proc resetall
aplayer -> playerreset
ascore -> scorereset
for i : 1 .. aplatform (upper (aplatform )) -> maxpform
aplatform (i ) -> resetplatform
end for
end resetall
end reset
%SET UP RESET VARIABLE
var areset : ^reset
new reset, areset |
You could just have the procedure like this
Turing: |
%CALLS ALL RESET PROCEDURES
proc resetall
aplayer -> playerreset
ascore -> scorereset
for i : 1 .. aplatform (upper (aplatform )) -> maxpform
aplatform (i ) -> resetplatform
end for
end resetall |
Objects aren't always better.
|
|
|
|
|
|
|
|