TGC Codebase Backup



2D Movement and Shooting by Stormwire

11th Oct 2010 21:42
Summary

A basic setup for a 2D shooter. No media.



Description

2D shooter setup. With this code you can create your own 2D shooter.



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    //Created by john Lafferty for www.darkbasicblog.com

rem Setting up the variables we will need

posx = 320
posy = 240

bulletx = -10
bullety = -10
bulletsym$ = "|"

bulletflag = 0

do
    
    cls
    
    set text size 20
    
// Data needed for debuging
    
    text 0,0,"Posx = "+str$(posx)
    text 0,12,"Posy = "+str$(posy)
    
    text 0,26,"Bullet posx = "+str$(bulletx)
    text 0,40,"Bullet posy = "+str$(bullety)
    
    set text size 40
    
// Make player 
    
    text posx,posy,"A"
    
// Control player
    
    if posy = -20 then posy = 490
    if upkey() = 1 then dec posy
    
    if posy = 490 then posy = -20
    if downkey() = 1 then inc posy
    
    if posx = -10 then posx = 650
    if leftkey() = 1 then dec posx
    
    if posx = 650 then posx = -10
    if rightkey() = 1 then inc posx
    
// Control bullet
    
    if spacekey() = 1 and bulletflag = 0
        
        bulletx = posx
        bullety = posy
        
        spacekey() = 0
        bulletflag = 1
        
    ENDIF
    
    if bulletflag = 1
    
        text bulletx,bullety,bulletsym$
        dec bullety,5
        
        if bullety <= -20
        
            bullety = -10
            bulletflag = 0
        ENDIF
        
    ENDIF
    
// Slow game
    
    wait 2
LOOP
end