Simple Platformer Help
Author |
Message |
Searing
|
Posted: Tue Dec 07, 2010 2:56 pm Post subject: Simple Platformer Help |
|
|
What is it you are trying to achieve?
I am trying to create a simple platformer in which a user can control a yellow oval to jump onto platforms.
What is the problem you are having?
I am having a lot of trouble creating a working system for the platformer. Right now, all screens other than my main menu are all just simple templates. The basic jumping up and falling down works fine, and the oval can jump on platforms, but I have yet to prevent the oval from jumping through platforms from under them or falling down after walking off a platform. Also, I am having trouble in my main program, wherein the procedure artificialGravityMainMenu is to go to LEDScreen back and forth until a user wishes to exit to an exit screen which closes the screen
Describe what you have tried to solve this problem
I have tried putting stricter restrictions and simplifying my if statements, and tries using less loops, but not much seems to work
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Here it is
Turing: |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%This program runs a small platform game in which you can control a series of%
%LEDs contained inside a box, connected to the computer, while controllong %
%"The Guy": the main character. %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Sets the screen to the needed specfications%
%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
setscreen ("nocursor")
%%%%%%%%%%%%%%%%%%%
%Program variables%
%%%%%%%%%%%%%%%%%%%
var theGuyMiddleX : int := 100
var theGuyMiddleY : int := 30
var anyKey, anyKey2 : string (1)
var keys : array char of boolean
var clearToJump : boolean
var jumpingNow, upKeyDown, goToExit, goToLEDs : boolean := false
var mainWinID : int := Window.Open ("position:center;center")
var titleFontID : int := Font.New ("Courier:20:bold")
var textFontID : int := Font.New ("Courier:12")
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Creates the forward procedures used in the program%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
forward procedure exitScreen
forward procedure LEDScreen
forward procedure mainMenu
forward procedure controlScreen
forward procedure artificialGravityMainMenu
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%This procedure pauses the program and awaits user input%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
procedure pauseProgram
%Asks for user input%
Font.Draw ("Press any key to continue", 0, 1, textFontID, white)
%Prevents previous screen keys from interfering%
delay (200)
%Waits for user Input%
locate (25, 42)
getch (anyKey )
end pauseProgram
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%This procedure produces the artificial gravity used throughout the main menu%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
body procedure artificialGravityMainMenu
mainMenu
goToLEDs := false
%Loops input/output%
loop
%Draws original guy to be modified%
drawfilloval (theGuyMiddleX, theGuyMiddleY, 10, 10, yellow)
%Recieves user input%
Input.KeyDown (keys )
%Keeps track of whether the Guy is on a platform%
if theGuyMiddleY = 60 and theGuyMiddleX < 15 then
goToExit := true
exitScreen
else
if theGuyMiddleY = 60 and theGuyMiddleX > 620 then
goToLEDs := true
LEDScreen
end if
end if
%Keeps track of whether The Guy can jump%
if theGuyMiddleY = 30 or theGuyMiddleY = 60 then
clearToJump := true
else
clearToJump := false
end if
%Keeps track of whether the up key is pressed%
if keys (KEY_UP_ARROW) then
upKeyDown := true
else
upKeyDown := false
end if
%Guy jumps up%
if keys (KEY_UP_ARROW) and clearToJump = true or jumpingNow = true then
drawfilloval (theGuyMiddleX, theGuyMiddleY, 10, 10, white)
drawfilloval (theGuyMiddleX, theGuyMiddleY + 10, 10, 10, yellow)
theGuyMiddleY := theGuyMiddleY + 10
jumpingNow := true
delay (10)
end if
%Gravity causes guy to fall back down%
if theGuyMiddleY >= 100 or jumpingNow = true and upKeyDown = false then
loop
drawfilloval (theGuyMiddleX, theGuyMiddleY, 10, 10, white)
drawfilloval (theGuyMiddleX, theGuyMiddleY - 10, 10, 10, yellow)
theGuyMiddleY := theGuyMiddleY - 10
delay (100)
exit when theGuyMiddleY = 30 or theGuyMiddleX < 51 and theGuyMiddleY = 60 or theGuyMiddleX > 580 and theGuyMiddleY = 60
end loop
jumpingNow := false
end if
%Guy goes left%
if keys (KEY_LEFT_ARROW) and theGuyMiddleX > 10 then
drawfilloval (theGuyMiddleX, theGuyMiddleY, 10, 10, white)
drawfilloval (theGuyMiddleX - 10, theGuyMiddleY, 10, 10, yellow)
theGuyMiddleX := theGuyMiddleX - 10
delay (100)
end if
%Guy goes right%
if keys (KEY_RIGHT_ARROW) and theGuyMiddleX < 629 then
drawfilloval (theGuyMiddleX, theGuyMiddleY, 10, 10, white)
drawfilloval (theGuyMiddleX + 10, theGuyMiddleY, 10, 10, yellow)
theGuyMiddleX := theGuyMiddleX + 10
delay (100)
end if
View.Update
exit when goToExit = true or goToLEDs = true
%Ends input/output loop%
end loop
end artificialGravityMainMenu
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%This procedure draws the introductory screen%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
procedure introduction
cls
%Draws the background%
drawfillbox (0, 0, 639, 399, black)
drawfilloval (320, 250, 50, 50, yellow)
%Draws title text%
Font.Draw ("THE GUY", 250, 380, titleFontID, white)
%Awaits input%
pauseProgram
controlScreen
end introduction
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%This procedure draws the control screen%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
body procedure controlScreen
cls
%Draws the background%
drawfillbox (0, 0, 639, 399, black)
%Draws title text and controls text%
Font.Draw ("THE GUY", 250, 380, titleFontID, white)
Font.Draw ("Use the arrow keys to control The Guy!", 10, 100, textFontID, white)
%Awaits Input%
pauseProgram
artificialGravityMainMenu
end controlScreen
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%This procedure draws the basic graphics in the main menu%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
body procedure mainMenu
cls
%Draws the background%
drawfillbox (0, 0, 639, 399, white)
drawfillbox (0, 0, 639, 19, green)
%Draws title text%
Font.Draw ("THE GUY", 250, 380, titleFontID, black)
%Draws the platforms%
drawfillbox (0, 41, 40, 49, brown) %Left platform%
drawfillbox (639, 41, 599, 49, brown) %Right platform%
%Labels the platforms%
locate (15, 1)
put "Exit"
locate (15, 77)
put "LEDs"
end mainMenu
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%This procedure draws the exit screen%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
body procedure exitScreen
cls
%Draws the background%
drawfillbox (0, 0, 639, 399, black)
%Locates and draws text%
Font.Draw ("THE GUY", 250, 380, titleFontID, white)
%Gets user input%
pauseProgram
%Closes window%
Window.Close (mainWinID )
end exitScreen
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%This procedure draws the LED screen%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
body procedure LEDScreen
drawfillbox (0, 0, 639, 399, black)
%Locates and draws text%
Font.Draw ("THE GUY", 250, 380, titleFontID, white)
pauseProgram
artificialGravityMainMenu
end LEDScreen
%%%%%%%%%%%%%%
%Main program%
%%%%%%%%%%%%%%
introduction
artificialGravityMainMenu
%%%%%%%%%%%%%%%%%%%%
%End of the program%
%%%%%%%%%%%%%%%%%%%%
|
Please specify what version of Turing you are using
4.1.1 |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Sur_real
|
Posted: Tue Dec 07, 2010 9:47 pm Post subject: Re: Simple Platformer Help |
|
|
You should look into the whatdotcolor function and collision detection. It'll make your life that much easier.
I mean the way you're doing it is sort of like hard coding (every level will require a whole new set of coordinates) |
|
|
|
|
|
Searing
|
Posted: Wed Dec 08, 2010 12:44 pm Post subject: Re: Simple Platformer Help |
|
|
How exactly does collision detection work?
And how would whatdotcolour help me in my program? |
|
|
|
|
|
|
|