Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Help with platformer game
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
saltpro15




PostPosted: Mon Jan 12, 2009 12:56 pm   Post subject: Help with platformer game

Alright, so I made this little platformer game out of boredom. I originally had all the code in one mega loop, but now I want to create random levels, so I switched to procedures. The problem now is that I need a cls command in my game procedure, which then wipes the level out and for some reason Turing doesn't see fit to redraw it -.- . Any help would be appreciated.


jump program.t
 Description:

Download
 Filename:  jump program.t
 Filesize:  1.67 KB
 Downloaded:  87 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Laplace's Demon




PostPosted: Mon Jan 12, 2009 1:11 pm   Post subject: Re: Help with platformer game

Heres a working version, should be easy to see what I swapped around.

Turing:


%game program in the works

setscreen ("graphics:640;480,offscreenonly")

%worlds biggest procedure, with help from compsci

var y := Rand.Int (120, 320)
var x := Rand.Int (120, 320)
var b := Rand.Int (340, 370)
var v := Rand.Int (120, 350)
var col := Rand.Int (1, 200)

%drawing the map
proc drawmap

    drawline (0, 120, maxx, 120, black)
    drawfillbox (maxx div 2.5, 120, x, y, col)
    drawfillbox (300, 120, b, v, col)
end drawmap

proc game

    var font1 : int

    const ground_height := 120
    const jump_speed := 20
    const run_speed := 10
    const gravity := 1

    var chars : array char of boolean
    var posx, posy : int
    var velx, vely : int
    var finx : int := 290
    var finy : int := 180
    var level : int := 1
    posx := 20
    velx := 0
    posy := 400
    vely := 0





    loop
        drawmap
        Input.KeyDown (chars)
        if chars (KEY_LEFT_ARROW) then
            velx := -run_speed
        elsif chars (KEY_RIGHT_ARROW) then
            velx := run_speed
        else
            velx := 0
        end if
        if chars (KEY_UP_ARROW) and posy = ground_height then
            vely := jump_speed
        end if




        vely -= gravity
        posx += round (velx)
        posy += round (vely)


        if posy < ground_height then
            posy := ground_height
            vely := 0
        end if


        if posy = ground_height then
            drawfillbox (posx - 10, posy, posx + 10, posy + 20, red)
        else
            drawfillbox (posx - 10, posy, posx + 10, posy + 20, red)
        end if


        View.Update
        delay (20)
        cls





    end loop
end game





%collision detection code goes here (still to be finished)



%main loop xD
loop

    drawmap
    game

end loop

saltpro15




PostPosted: Mon Jan 12, 2009 3:11 pm   Post subject: RE:Help with platformer game

ohhh, well now I feel stupid xD thanks man
saltpro15




PostPosted: Mon Jan 12, 2009 3:15 pm   Post subject: RE:Help with platformer game

+bits btw
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: