Road Fighter Game

freeBASIC source code examples by FbCadcam staff and interns

Moderators: yajra1219, Jayem, kitty_webb, Ywsp, joanCruz03, shela

Post Reply
markremetio123
Posts: 49
Joined: Fri Oct 05, 2018 6:48 am

Road Fighter Game

Post by markremetio123 » Mon Mar 11, 2019 5:31 am

Here is the simple road fighter game version 1
Still working on progress...
Here is the link of the zip file
http://fbcadcam.com/fbcadcamph/folders/ ... ad_fighter

Code: Select all

#Include once "fmod.bi"
#Include "fbgfx.bi"
#if __FB_LANG__="fb"
Using FB 
#EndIf
ScreenRes(400,600,32,2)
Window(0,0)-(399,599)
Dim As Any Ptr car_img = ImageCreate(48,84)
Dim As Any Ptr enemy_car_img=ImageCreate(48,84)
Dim As Any Ptr road_img=ImageCreate(400,1420)
Dim As Any Ptr bg=ImageCreate(52,88)
Type car_attributes
	As Integer x
	As Integer y
	As Double speed
End Type
Type enemy_car_attributes
	As Integer x
	As Integer y
	As Double speed
End Type
Type road_attributes
	As Integer x
	As Integer y
	As Double speed
End Type
BLoad"road2.bmp",road_img
BLoad"car_red.bmp",car_img
BLoad"enemy_car.bmp",enemy_car_img
Dim enemy_car_player As enemy_car_attributes
Dim car_player As car_attributes
Dim road As road_attributes
Dim car_move As Integer
Dim As Integer distance,finish


'initialize the values here
distance=0
finish=1000
car_player.x = 180
car_player.y = 100
enemy_car_player.x=50
enemy_car_player.y=700
road.x=0
road.y=1400
car_move=0

'''''''''''''''''''''''''''

Do

Put(road.x,road.y),road_img,Trans	
If car_player.x>=345 Then 
	car_player.x=345
	car_player.speed-=.2
EndIf

If car_player.x<=5 Then 
	car_player.x=5
	car_player.speed-=.2
EndIf
If car_player.y>=500 Then
	car_player.y=500
EndIf
If car_player.y<=90 Then 
	car_player.y=90
EndIf

If road.y<=700 Then road.y=1400
If car_move=0 Then 
	car_player.speed-=.1
EndIf
If car_move=1 Then 
		road.y-=car_player.speed
EndIf
If car_player.speed<=0 Then car_player.speed=0 

If MultiKey(SC_UP) Then	
	car_player.y+=car_player.speed
	car_move=1
	car_player.speed+=.1
EndIf

If MultiKey(SC_DOWN)Then	
	car_player.y-=5
	car_player.speed-=.2
EndIf

If MultiKey(SC_LEFT)Then	car_player.x-=5
If MultiKey(SC_RIGHT)Then	car_player.x+=5
Draw String(15,580),"Lives:",RGB(255,255,255)
Draw String(150,580),"Time:",RGB(255,255,255)
Draw String(290,580),"Score:",RGB(255,255,255)
Draw String(300,15),"Speed:",RGB(255,255,255)
Dim As Integer x, y, buttons, res 
enemy_car_player.y+=1

 Locate 1, 1
 Print car_player.x;car_player.y;road.x;road.y;"speed:";car_player.speed
Get(car_player.x,car_player.y)-(car_player.x+48,car_player.y-84),bg
Put(enemy_car_player.x,enemy_car_player.y),enemy_car_img,Trans

Put(car_player.x,car_player.y),car_img,Trans
Sleep 10
Put(car_player.x,car_player.y),bg,Pset
Sleep 10
Loop While InKey<>Chr(27)

End

owen
Site Admin
Posts: 656
Joined: Thu Apr 13, 2017 12:14 pm

Re: Road Fighter Game

Post by owen » Wed Mar 20, 2019 9:15 am

Thank you for sharing your code and for your efforts.
I hope other kids can see examples like this in the future and begin to be curios enough to write their own programs.

Post Reply