TGC Codebase Backup



2D Rock Shot by blood scent

17th May 2006 16:06
Summary

Well, i wanted to make a game so i made this. Um let me just say it isn't a blockbuster or anything.If you would like an OK toturial on a lot of different topics, analyze my code.



Description

Basically you move with left and write, and press up to shoot. If you hit the bottom square guy, the bullet is absorbed. This game is only a semi challenge if you try to not stay still. It also records the amount of shots it took you to win. The goal is to shoot the top one. If you think I should change it so that it has health please email me (frankietheg123@yahoo.com). Oh yeah, when you lose i make you feel even worse by making the words you lose bounce around the screen. I remmed out the media so dont worry, just enjoy.



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    REM Project: created bitmap
REM Created: 8/17/2005 8:05:15 PM
REM
REM ***** Main Source File *****
REM
REM Project: created bitmap
REM Created: 8/17/2005 8:05:15 PM
REM
REM ***** Main Source File *****
setupsprites()
control_gameplay()
end

rem setup game
function setupsprites()
rem initialize
randomize timer()
hide mouse
sync on : sync rate 100
rem load music "mp3music misty room.mp3",1
rem loop music 1
enemy#=4

rem draw the figures
create bitmap 2,100,100
set current bitmap 2
ink rgb(255,255,255),rgb(15,204,14)
sync : cls : sync

rem cannon base
box 10,0,20,10

rem cannon body
line 15,10,15,35


rem left cannon leg
line 15,35,4,40

rem right cannon leg
line 15,35,26,40

get image 2,0,0,40,60

rem get rocks
cls rgb(255,0,0)
ink rgb(255,0,0),rgb(0,0,0)
cls rgb(0,0,0)
sync
circle 10,10,10
get image 3,0,0,22,22
cls rgb(255,0,0)
ink rgb(255,0,0),rgb(0,0,0)
cls rgb(0,0,0)
sync
circle 10,10,10
get image 5,0,0,22,22

rem get enemy
cls
sync
ink rgb(10,0,0),rgb(0,0,0)
box 0,0,20,20
get image enemy#,0,0,21,21
set current bitmap 0
ink rgb(255,255,255),rgb(0,0,0)
sync : cls rgb(0,0,0) : sync

rem make sprite cannon and rock sprites

rem draw cannon
sprite 2,screen width()-45,screen height()-80,2

rem draw cannon bullet
sprite 3,screen width()-70,screen height()-140,3

rem draw enemys bullet
sprite 5,20,20,5
hide sprite 5
scale sprite 5,80

rem draw enemy
sprite 4,1,1,4
rem draw second enemy
clone sprite 4,6
set sprite diffuse 3,0,0,0
rotate sprite 2,180
rotate sprite 2,180

rem draw to screen
sync
endfunction

rem animation function
function control_gameplay()
shoot#=0
shots#=0
enemy#=4
rem cannon and rock and enemy positions

rem rock
y#=screen height()-80
y3#=screen height()-140

rem enemys
xpos#=1
xpos2#=screen width()-50
ypos2#=30
y2pos#=30

rem setup x positions

rem your bullet
x#=screen width()-70

rem you
x2#=screen width()-45

ypos#=10
y5#=ypos#

rem enemy bullet
bullet#=rnd(screen width()-30)

rem color screen
ink rgb(255,255,255),rgb(0,0,0)
sync : cls rgb(0,0,0) : sync

rem main game loop
do
rem ground
rem line 0,screen height()-55,screen width()+100,screen height()-55

rem move left
if leftkey()=1 and x#>14
if shoot#=0 then x#=x#-5
if x2#>34 then x2#=x2#-5
if shoot#=0 then sprite 3,x#,y3#,3
sprite 2,x2#,y#,2
endif

rem walk right
if rightkey()=1 and x#<screen width()-25
if shoot#=0 then x#=x#+5
if x2#<screen width()-5 then x2#=x2#+5
if shoot#=0 then sprite 3,x#,y3#,3
sprite 2,x2#,y#,2
endif

rem tell game to shoot
if upkey()=1 and y3#=screen height()-140
shoot#=1
shots#=shots#+1
endif

rem shoot
if shoot#=1
y3#=y3#-5
sprite 3,x#,y3#,3
endif

rem return bullet
if y3#<-90
y3#=screen height()-140
x#=x2#-25
shoot#=0
rem draw bullet and cannon
sprite 3,x#,y3#,3
sprite 2,x2#,y#,2
endif

rem make sure cannon is under bullet
if shoot#=0 then x#=x2#-25

rem move enemy

rem move bounce right
if xpos#<=0 and w=0
w=1
xpos#=xpos#+5
endif

rem move right
if xpos#<screen width()-30 and w=1
xpos#=xpos#+5
endif

rem bounce left
if xpos#>=screen width()-30 and w=1
w=0
xpos#=xpos#-5
endif

rem move left
if xpos#>0 and w=0
xpos#=xpos#-5
endif
sprite 4,xpos#,1,4

rem move enemy 2

rem move bounce right
if xpos2#<=0 and q=0
q=1
if ypos2#=y2pos# then xpos2#=xpos2#+5
endif

rem move right
if xpos2#<screen width()-30 and q=1
if ypos2#=y2pos# then xpos2#=xpos2#+5
endif

rem bounce left
if xpos2#>=screen width()-30 and q=1
q=0
if ypos2#=y2pos# then xpos2#=xpos2#-5
endif

rem move left
if xpos2#>0 and q=0
if ypos2#=y2pos# then xpos2#=xpos2#-5
endif
sprite 6,xpos2#,ypos2#,4

rem check for win collision
if sprite hit(4,3)
shots$=str$(shots#)
set cursor screen width()/2,screen height()/2+20
sync
center text screen width()/2,screen height()/2,shots$ : center text screen width()/2,screen height()/2+20,"shots taken" : center text screen width()/2,screen height()/2+40,"press any key"
sync
wait key

rem start bouncing text
mytext$="YOU WIN"
set text font "times new roman"
set text size 36
ink rgb(255,0,0),rgb(10,10,10)
width=text width(mytext$)
height=text height(mytext$)
currentx=320-width/2
currenty=240-height/2
speedx=2
speedy=-2

rem control bouncing text
do
cls
currentx=currentx+speedx
if currentx+width>635 then speedx=-4
if currentx<5 then speedx=4

currenty=currenty+speedy
if currenty+height>475 then speedy=-4
if currenty<5 then speedY=4

text currentx,currenty,mytext$

sync
rem restart bounce
loop
end
endif
rem end check

rem check to see if enemy should shoot
if sprite x(4)=bullet# or sprite x(4)=bullet#+1 or sprite x(4)=bullet#-1 or sprite x(4)=bullet#-2 or sprite x(4)=bullet#+2
show sprite 5
sprite 5,bullet#-10,ypos#,5
ypos#=ypos#+7
rem end check
endif

rem make enemy shoot itself
if ypos2#=y2pos#
if sprite x(6)=sprite x(2) or sprite x(6)=sprite x(2)+1 or sprite x(6)=sprite x(2)-1
ypos2#=ypos2+10
endif
endif

if y2pos#<>ypos2#
ypos2#=ypos2#+7
endif

if ypos2#>screen height()-1
ypos2#=y2pos#
endif

rem move enemy bullet
if y5#<>ypos#
ypos#=ypos#+7
endif

rem return bullet
if ypos#>screen height()-5
hide sprite 5
ypos#=y5#
endif

rem return bullet
if sprite y(5)>screen height()-5
hide sprite 5
endif

vis#=sprite visible(5)
rem make new position
if vis#=0 then bullet#=sprite x(2)
sprite 5,bullet#-10,ypos#,5

rem check for loss
if sprite hit(5,2)
mytext$="YOU LOSE"
set text font "times new roman"
set text size 36
ink rgb(255,0,0),rgb(10,10,10)
width=text width(mytext$)
height=text height(mytext$)
currentx=320-width/2
currenty=240-height/2
speedx=2
speedy=-2
do
cls
currentx=currentx+speedx
if currentx+width>635 then speedx=-4
if currentx<5 then speedx=4

currenty=currenty+speedy
if currenty+height>475 then speedy=-4
if currenty<5 then speedY=4

text currentx,currenty,mytext$

sync
loop

endif

rem check for enemy loss collision
if sprite hit(2,6)=1
mytext$="YOU LOSE"
set text font "times new roman"
set text size 36
ink rgb(255,0,0),rgb(10,10,10)
width=text width(mytext$)
height=text height(mytext$)
currentx=320-width/2
currenty=240-height/2
speedx=2
speedy=-2
do
cls
currentx=currentx+speedx
if currentx+width>635 then speedx=-4
if currentx<5 then speedx=4

currenty=currenty+speedy
if currenty+height>475 then speedy=-4
if currenty<5 then speedY=4

text currentx,currenty,mytext$

sync
loop
endif

if sprite hit(6,3)
y3#=screen height()-140
ypos2#=y2pos#
shoot#=0
endif

rem draw to  screen
sync

rem go back to do
loop
endfunction