This is small Basic 2D shooter and it isn't perfect but it just a start :)
; Name of the Game - HELLFIRE
; ------------------------------------------------
; (1) Add title screen and Game over screen too.
; (2) Level Select
; (3) Add Score
; (4) Add Hiscore
; ------------------------------------------------
;Game Version 1.0
Graphics 800, 600
SetBuffer BackBuffer()
Global fntArial
Global player_x=5
Global player_y=280
Global lifes
Global bullet_x, bullet_y
Global bullet_enabled
Global Title=False
Global Level$ = "Very Easy"
Global Levels
Global Score
Global Hi_Score =250
Global Font1
Global Font2
Global FirstX, LastX
Global FirstY, LastY
Font1=LoadFont("Arial",20,True,True,False)
Font2=LoadFont("Arial",120,True,True,False)
Score =0
Levels =1
Level$ = "Very Easy"
bullet_x = player_x
bullet_y = player_y
bullet_enabled = False
; The rock Type
Type Rock
Field x,y
Field destroyed
End Type
Title=False
endgame=False
Repeat
Cls
If Title=False
If KeyHit( 1 )
endgame=True
EndIf
lifes = 100
Intro()
Else
If KeyHit( 1 )
title=False
EndIf
Draw_Rock()
Draw_Player()
Draw_bullets()
EndIf
If Lifes<=0 Then Game_over() : Title=False
count_rock=0
For pointer_rock.rock=Each rock
count_rock=count_rock+1
Next
disp_text$=" Rocks: "+count_rock+" "
disp_text_width=StringWidth( disp_text )
disp_text_height=StringHeight( disp_text )
Color 0,0,0
Rect GraphicsWidth()-disp_text_width,GraphicsHeight()-disp_text_height , disp_text_width,disp_text_height , True
Color 128,192,255
Text GraphicsWidth()-disp_text_width,GraphicsHeight()-disp_text_height , disp_text , False,False
Flip
Until endgame
FreeFont Font1
FreeFont Font2
End
Function Intro()
player_x=5
player_y=280
Level$ = Level$
For value = 0 To 255
red = 255 - value
green = 225
blue = value
Color red , green , blue
; Convert color position to vertical position
relative = value * GraphicsHeight () / 255
Rect 0 , lastheight , GraphicsWidth () , relative
; Remember previous vertical position
lastheight = relative
Next
Color 0,0,255
If KeyHit(205) Then Levels=Levels+1 ;;
If KeyHit(203) Then Levels=Levels-1 ;;
If Levels<1 Then Levels =1
If Levels=>3 Then Levels =3
SetFont Font2
Text 375,115, "HELLFIRE",True,True
SetFont Font1
Text 375,250, "H i - S c o r e : "+Hi_Score,True
Text 375,215, "Diffcult level:"+Level$,True
Text 275,290, "Programming "
Text 275,315, "by G r a h a m "
Text 175,450, "Move Arrow left to right to choose the Diffcult level",False,False
Text 375,515, "Press Spacebar to Start",True,True
Select Levels
; Very Easy
Case 1
Level$="Very Easy"
FirstX =1 : LastX =99000
FirstY =1 : LastY =600
; Medium
Case 2
Level$="Medium"
FirstX =1 : LastX =6000
FirstY =1 : LastY =600
; Very Hard
Case 3
Level$="Very Hard"
FirstX =1500 : LastX =3000
FirstY =5 : LastY =580
End Select
If KeyDown(57)
;; delete each rock ;; A1a
For i = 0 To 150
r.rock = New Rock ; Create rocks
r\x = Rand(FirstX,LastX) ; The starting X
r\y = Rand(FirstY,LastY) ; The starting Y
r\destroyed = False
Next
Title =True
EndIf
;; Flip
End Function
Function Draw_Rock()
; Set color for the rocks
Color 255,80,10
;--------------Draw rocks----------------
For r.rock = Each Rock
Rect r\x,r\y,20,20
r\x = r\x - 10
If r\x < 0 Then ; If the rocks reaches the left
r\x = Rand(580,950) ; of the screen, draw
r\y = Rand(1,580) ; it at the left
EndIf
If RectsOverlap(player_x,player_y,30,15,r\x,r\y,20,20) Then
lifes = lifes - 1
If lifes =< 0 Then
player_x = -100
player_y = -100
EndIf
EndIf
If RectsOverlap(bullet_x,bullet_y,5,2,r\x,r\y,20,20) Then
Score=Score+1
Delete r.rock
bullet_enabled = False
bullet_x = player_x + 5
bullet_y = player_y + 10
EndIf
Next
End Function
Function Draw_Player()
Color 10,150,10
Rect player_x,player_y,30,15 ; Draw player
If KeyDown(208) Then player_y = player_y + 7 ; Go up
If KeyDown(200) Then player_y = player_y - 7 ; Go down
If player_y < 0 Then player_y = 0
If player_y > 585 Then player_y = 585
End Function
Function Draw_bullets()
If KeyHit(57) Then
bullet_enabled = True
bullet_x = player_x + 5
bullet_y = player_y + 10
EndIf
If bullet_enabled = True Then
bullet_x = bullet_x + 15
Rect bullet_x,bullet_y,5,2
EndIf
SetFont Font1
Color 255,255,255
Text 300,5, "Lifes remaining: " + lifes,False
Text 100,5, "Score: " + Score,False
If Score>Hi_Score Then Hi_Score=Score
Text 700,5, "Hi - Score: "+Hi_Score,True
End Function
Function Game_Over()
Cls
For value = 0 To 255
red = 255 - value
green = 150
blue = value
Color red , green , blue
; Convert color position to vertical position
relative = value * GraphicsHeight () / 255
Rect 0 , lastheight , GraphicsWidth () , relative
; Remember previous vertical position
lastheight = relative
Next
Color 0,0,255
SetFont Font2
Text 375,315, "Game Over",True,True
SetFont Font1
Flip
Delay 1000
FlushKeys
End Function
|