help with jumping in my game
Author |
Message |
lufthansa747
|
Posted: Mon Dec 21, 2009 8:58 am Post subject: help with jumping in my game |
|
|
What is it you are trying to achieve?
i want the guy to be able to jump the same height he jumps now witch gives him the ability to land on the block above him, but he is able to jump around 6 blocks side ways. i only want him to jump around 2 or 3 , 4 the max.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) Turing: | "turing"]
View.Set ("graphics:1000;700,nobuttonbar,nocursor")
%Creates a class for your guy
class yourPlayer
export changeX, changeY, x, y
%Defines variables for the player
var x : int
var y : int
%Alows the value of x to be changed out side of the class
%Params : newX - the new value you want x to be
% add - if true the value of newX is added to x. If false the value of x is set to newX
procedure changeX (newX : int, add : boolean)
if add = true then
x + = newX
else
x := newX
end if
end changeX
%Alows the value of y to be changed out side of the class
%Params : newY - the new value you want y to be
% add - if true the value of newY is added to y. If false the value of y is set to newY
procedure changeY (newY : int, add : boolean)
if add = true then
y + = newY
else
y := newY
end if
end changeY
end yourPlayer
%Creates a 2d array representing the map
%Params : level - The level you want built
%Returns the info of the text file in an 2d array
function createVirtualMap (level : int) : array 0 .. 16, 0 .. 13 of string
var txtLine : string
var virtualMap : array 0 .. 16, 0 .. 13 of string
var fileName : int
open : fileName, "Level" + intstr (level ) + ".txt", get
%Goes throught every char of the txt file
for row : 0 .. 13
get : fileName, txtLine
for column : 0 .. 16
virtualMap (column, row ) := txtLine (column + 1)
end for
end for
close : fileName
result virtualMap
end createVirtualMap
%Creates pic and sprite variable
var guySprite, player1 : int
player1 := Pic.FileNew ("StickMan.gif")
guySprite := Sprite.New (player1 )
%Creates player
var player : pointer to yourPlayer
new yourPlayer, player
%Draws the level
%Params: virtualMap - the 2d array where the txt file data is stored
procedure drawMap (virtualMap : array 0 .. 16, 0 .. 13 of string)
for row : 0 .. 13
for column : 0 .. 16
if virtualMap (column, row ) = "1" then
var grassBlockPic : int := Pic.FileNew ("NormalGrassBlock.bmp")
Pic.Draw (grassBlockPic, column * 50, (13 - row ) * 50, picMerge)
Pic.Free (grassBlockPic )
elsif virtualMap (column, row ) = "2" then
var noGrassBlockPic : int := Pic.FileNew ("NormalDirtBlock.bmp")
Pic.Draw (noGrassBlockPic, column * 50, (13 - row ) * 50, picMerge)
Pic.Free (noGrassBlockPic )
elsif virtualMap (column, row ) = "3" then
var coinPic : int := Pic.FileNew ("Coin.gif")
Pic.Draw (coinPic, column * 50, (13 - row ) * 50, picMerge)
Pic.Free (coinPic )
elsif virtualMap (column, row ) = "4" then
var keyPic : int := Pic.FileNew ("Key.gif")
Pic.Draw (keyPic, column * 50, (13 - row ) * 50, picMerge)
Pic.Free (keyPic )
elsif virtualMap (column, row ) = "5" then
var doorPic : int := Pic.FileNew ("Door.gif")
Pic.Draw (doorPic, column * 50, (13 - row ) * 50, picMerge)
Pic.Free (doorPic )
elsif virtualMap (column, row ) = "G" then
player -> changeX (column * 50, false)
player -> changeY ((13 - row ) * 50, false)
Sprite.SetPosition (guySprite, player -> x, player -> y, false)
Sprite.Show (guySprite )
end if
end for
end for
Draw.Line (850, 0, 850, maxy, black)
end drawMap
%Draws the main screen
%No params
procedure drawMainScreen ()
end drawMainScreen
%Waits for the user to press a button on the main screen
%No params
%returns what button was pressed
% function waitForButtonPressed () : string
%
% end wait/ForButtonPress
%
%
%
function isMoveAllowed (valueOfVirtual : string) : boolean
result (valueOfVirtual = "0" or valueOfVirtual = "3" or valueOfVirtual = "5" or valueOfVirtual = "G")
end isMoveAllowed
%Define variables
var gravity : real := 9. 8
var velocity : real := 1
var fallTime : int := 0
var virtualMap : array 0 .. 16, 0 .. 13 of string
var keysPressed : array char of boolean
var level : int := 1
var leftSideCheck : string
var rightSideCheck : string
var topLSideCheck : string
var topRSideCheck : string
var xMove : int := 8
var yCalc : int
%Give virtualMap a value of " "
for row : 0 .. 13
for column : 0 .. 16
virtualMap (column, row ) := " "
put virtualMap (column, row )
end for
end for
%Draw the main menu screen
%Draw the level
virtualMap := createVirtualMap (level )
drawMap (virtualMap )
%Lets you play the game
loop
Input.KeyDown (keysPressed )
if keysPressed (KEY_UP_ARROW) and velocity = 0 then
velocity := - 10
end if
if keysPressed (KEY_RIGHT_ARROW) and player -> x + 29 + xMove < 850 then
rightSideCheck := virtualMap (floor ((player -> x + 29 + xMove ) / 50), 13 - floor (player -> y / 50))
topRSideCheck := virtualMap (floor ((player -> x + 29 + xMove ) / 50), 13 - floor (player -> y / 50) - 1)
if isMoveAllowed (rightSideCheck ) and isMoveAllowed (topRSideCheck ) then
player -> changeX (xMove, true)
Sprite.SetPosition (guySprite, player -> x, player -> y, false)
end if
end if
if keysPressed (KEY_LEFT_ARROW) and player -> x - xMove >= 0 then
leftSideCheck := virtualMap (floor ((player -> x - xMove ) / 50), 13 - floor (player -> y / 50))
topLSideCheck := virtualMap (floor ((player -> x - xMove ) / 50), 13 - floor (player -> y / 50) - 1)
if isMoveAllowed (leftSideCheck ) and isMoveAllowed (topLSideCheck ) then
player -> changeX (-xMove, true)
Sprite.SetPosition (guySprite, player -> x, player -> y, false)
end if
end if
%Checks if there is ground below player and calculates velocity
if velocity > 0 then
if player -> y - velocity >= 0 and player -> y + velocity <= maxy and Time.Elapsed > fallTime + 20 then
fallTime := Time.Elapsed
leftSideCheck := virtualMap (floor (player -> x / 50), 13 - floor ((player -> y - velocity ) / 50))
rightSideCheck := virtualMap (floor ((player -> x + 29) / 50), 13 - floor ((player -> y - velocity ) / 50))
if isMoveAllowed (leftSideCheck ) and isMoveAllowed (rightSideCheck ) then
player -> changeY (round (-velocity ), true)
Sprite.SetPosition (guySprite, player -> x, player -> y, false)
velocity + = gravity * (50 / 1000)
elsif (velocity = 1) then
velocity := 0
else
velocity := 1
end if
elsif (velocity = 1) then
velocity := 0
else
velocity := 1
end if
else
if player -> y - velocity + 54 <= maxy and Time.Elapsed > fallTime + 20 then
fallTime := Time.Elapsed
leftSideCheck := virtualMap (floor (player -> x / 50), 13 - floor ((player -> y + 54 - velocity ) / 50))
rightSideCheck := virtualMap (floor ((player -> x + 29) / 50), 13 - floor ((player -> y + 54 - velocity ) / 50))
if isMoveAllowed (leftSideCheck ) and isMoveAllowed (rightSideCheck ) then
player -> changeY (round (-velocity ), true)
Sprite.SetPosition (guySprite, player -> x, player -> y, false)
velocity + = gravity * (50 / 1000)
else
velocity := 1
yCalc := (floor ((player -> y + 54 - velocity ) / 50)) * 50 - 4
player -> changeY (yCalc, false)
Sprite.SetPosition (guySprite, player -> x, player -> y, false)
end if
else
player -> changeY (maxy - 54, false)
velocity := 1
Sprite.SetPosition (guySprite, player -> x, player -> y, false)
end if
end if
%Checks if you got a coin
if virtualMap (floor (player -> x / 50), 13 - floor (player -> y / 50) - 1) = "3" then
virtualMap (floor (player -> x / 50), 13 - floor (player -> y / 50) - 1) := "0"
var NoBlockPic : int := Pic.FileNew ("NoBlock.bmp")
Pic.Draw (NoBlockPic, floor (player -> x / 50) * 50, (floor (player -> y / 50)) * 50 + 50, picCopy)
Pic.Free (NoBlockPic )
end if
View.Update
delay (40)
end loop
|
[size=14]Please specify what version of Turing you are using
4.1.1
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
lufthansa747
|
Posted: Mon Dec 21, 2009 9:02 am Post subject: Re: help with jumping in my game |
|
|
forgot allot of pics so here is the whole program
Description: |
|
![](http://compsci.ca/v3/pafiledb/images/icons/clip.gif) Download |
Filename: |
Game.rar |
Filesize: |
15.08 KB |
Downloaded: |
59 Time(s) |
|
|
|
|
|
![](images/spacer.gif) |
|
|