Osallistun.
Code: Select all
Type LINES
Field x
Field y
Field w
End Type
Type BOXZ
Field x
Field y
End Type
bg=MakeImage(400,400)
DrawToImage bg
For y = 0 To 400 Step 4
r=50+y/3.0
g=255-y/4.0
b=255
Color r,g,b
Box 0,y,400,4
Next y
DrawToScreen
Global _TXT As String,_TXT2 As String,points,collision As Byte, game_started,ukko_x As Float,ukko_y As Float,ukko_speed_y As Float,ukko_speed_x As Float
Global newgame,making_new_line,width,start_x,start_y
ukko_x = 0.0
ukko_y = 0.0
ukko_speed_y = 0.0
making_new_line = False
ClsColor cbwhite
Cls
Const UKKO_WIDTH = 10
Const UKKO_HEIGHT = 15
NewLine(-50,0,250)
game_started = True
ukko_x=-30
ukko_y=70
ukko_speed_y=0
points=0
Dim sfx(1)
sfx(0)=LoadSound("Media\Blaster.wav")
SetFont LoadFont("impact",24,1)
SetWindow "BOXZ"
game_started=False
newgame=Timer()+3000
_TXT="Press the Space Button to jump"
_TXT2="Hit left mouse button to draw levels"
_TXT3$="And try to collect all the boxes :)"
Repeat
DrawImage bg,0,CameraY()-100
MouseEvents()
GuyPhysics(False,True)
AddBoxes()
DrawBoxes()
DrawGuy()
DrawLines()
PositionCamera CurveValue(ukko_x,CameraX(),10.0),Min(Max(CurveValue(ukko_y,CameraY(),20.0),0),100)
If newgame Then
If Timer()>newgame Then
For iL.LINES = Each LINES
Delete iL
Next iL
For iB.BOXZ = Each BOXZ
Delete iB
Next iB
NewLine(-50,0,250)
game_started = True
ukko_x=-30
ukko_y=70
PositionCamera ukko_x,ukko_y
ukko_speed_y=0
ukko_speed_x=0
points=0
newgame=0
Else
CenterText 200,130,_TXT,2
CenterText 200,155,_TXT2,2
CenterText 200,190,_TXT3,2
EndIf
EndIf
DrawScreen
Forever
Function AddBoxes()
If Rand(1,100)=65 Then
n.BOXZ = New(BOXZ)
n\x = CameraX()+300
n\y = Rand(-100,200)
EndIf
End Function
Function DrawBoxes()
DrawToWorld ON
For iB.BOXZ = Each BOXZ
Color 230,230,230
Box iB\x-6,iB\y+6,12,12,0
Color 200,200,200
Box iB\x-5,iB\y+5,10,10,0
Color 170,120,120
Box iB\x-4,iB\y+4,8,8
If UkkoBoxOverlap(iB\x,iB\y) Then
Delete iB
sf=PlaySound(sfx(0))
SetSound sf,0,100,0,50000
points + 1
EndIf
If iB\x<CameraX()-250 Then Delete iB
Next iB
DrawToWorld OFF
End Function
Function UkkoBoxOverlap(x,y)
Return BoxOverlap(ukko_x-UKKO_WIDTH/2,ukko_y-UKKO_HEIGHT/2,UKKO_WIDTH,UKKO_HEIGHT,x,y,12,12)
End Function
Function MouseEvents()
If MouseDown(1) And MouseDown(2) = 0 Then
If making_new_line = False Then
making_new_line = True
start_x = MouseWX()
start_y = MouseWY()
EndIf
width = MouseWX()-start_x
DrawToWorld ON
Color 200,200,200
Box start_x+(width<0)*width,start_y,Abs(width),1
Color cbblack
DrawToWorld OFF
EndIf
If MouseDown(1) = 0 And making_new_line = True Then
making_new_line = False
NewLine(start_x+(width<0)*width,start_y,Abs(width))
EndIf
If MouseDown(2) Then making_new_line = False
If MouseHit(3) Then
game_started = Not game_started
If game_started Then
ukko_x=MouseWX()
ukko_y=MouseWY()
ukko_speed_y=0
ukko_speed_x=0
EndIf
EndIf
End Function
Function GuyPhysics(force_lk=0,force_rk=0)
If game_started Then
'lk=LeftKey() Or force_lk
rk=force_rk'*(1-lk*0.8)
If rk Or lk Then
ukko_speed_x = Min(Max(ukko_speed_x+(rk)*0.05*((collision=1)+(collision=0)*0.2),-2),2)
ElseIf collision = True Then
ukko_speed_x=CurveValue(0.0,ukko_speed_x,20.0)
Else
ukko_speed_x=CurveValue(0.0,ukko_speed_x,100.0)
EndIf
ukko_x = ukko_x + ukko_speed_x
x1=ukko_x-UKKO_WIDTH/4
x2=ukko_x+UKKO_WIDTH/4
y1=ukko_y+UKKO_HEIGHT/2
y2=ukko_y-UKKO_HEIGHT/2
collision = False
For iL.LINES = Each LINES
If ukko_speed_y<0.0 Then
x_col = (x1>=iL\x And x2<=iL\x+iL\w)
If x_col And iL\y<=y2 And iL\y>=y2+ukko_speed_y Then
ukko_y = iL\y+UKKO_HEIGHT/2
collision = True
EndIf
EndIf
Next iL
If Not collision Then
ukko_speed_y = ukko_speed_y - 0.04
ukko_y = ukko_y + ukko_speed_y
Else
ukko_speed_y = 0
EndIf
If KeyDown(cbkeyspace) And collision = True Then
ukko_speed_y = 2.0
EndIf
If ukko_y<-150 Then
game_started=False
newgame=Timer()+3000
_TXT="You got " + (points * 100) + " points!"
_TXT2=""
_TXT3=""
EndIf
EndIf
End Function
Function DrawGuy()
DrawToWorld ON
If game_started Then
Color 100,100,100
Box ukko_x-UKKO_WIDTH/2,ukko_y+UKKO_HEIGHT/2,UKKO_WIDTH,UKKO_HEIGHT,0
Circle ukko_x-UKKO_WIDTH/2,ukko_y+UKKO_HEIGHT*0.75,UKKO_WIDTH,0
Color 255,255,255
Circle ukko_x-UKKO_WIDTH/2+1,ukko_y+UKKO_HEIGHT*0.75-1,UKKO_WIDTH-2
Box ukko_x-UKKO_WIDTH/2+1,ukko_y+UKKO_HEIGHT/2-1,UKKO_WIDTH-2,UKKO_HEIGHT-2
Color 50,50,100
Box ukko_x+UKKO_WIDTH/4-1,ukko_y+UKKO_HEIGHT/2+1,2,2
Box ukko_x,ukko_y+1,UKKO_WIDTH/2,1
Dot ukko_x,ukko_y+2
EndIf
DrawToWorld OFF
End Function
Function DrawLines()
DrawToWorld ON
For iL.LINES = Each LINES
Color 255,255,255
Box iL\x,iL\y-1,iL\w,1
Color 0,0,0
Box iL\x-1,iL\y,iL\w+2,3,0
If iL\x+iL\w<CameraX()-200 Then Delete iL
Next iL
DrawToWorld OFF
End Function
Function NewLine(x,y,width)
n.LINES = New(LINES)
n\x = x
n\y = y
n\w = width
End Function