Author Topic: Blitz coding[BB2D]  (Read 375 times)

0 Members and 1 Guest are viewing this topic.

Offline Paul

  • Pentium
  • *****
  • Posts: 1490
  • Karma: 47
    • View Profile
Blitz coding[BB2D]
« on: April 11, 2007 »


Found this site today and did the first exercise

http://www.binarysurge.com/blitzhack/page.php?p=exercises

Here's my code, don't look at it if you're going to do the exercises.

Code: [Select]



















Graphics 800,600
SetBuffer BackBuffer()

Type enemy
Field x#,y#
Field xdir#,ydir#
Field let,col
End Type
timer=CreateTimer(70)
Global score,miss,mul#=1
While Not KeyHit(1)
If MilliSecs()-time>1000 Then newlet():time=MilliSecs()
Color 255,255,255
Text 0,0,"score: "+(level*100+score)
Text 0,20,"Misses:"+miss+"/"+5
If score=>100
score=0
level=level+1
mul#=mul#+0.1
Text 400,300,"Level "+(level+1),1,1
Flip
Delay 1000
miss=0
EndIf
If miss=>5 Then End
tmp$=Lower$(Chr$(GetKey()))
printlet(tmp$)
WaitTimer(timer)
Flip
Cls
Wend

Function printlet(tmp$)
oscore=score
For a.enemy= Each enemy
a\x=a\x+a\xdir#*mul
a\y=a\y+a\ydir#*mul
let=a\let
If let<65 Then let=let-7
Color a\col Shr 16 And $ff,a\col Shr 8 And $ff,a\col And $ff
Oval a\x-5,a\y-5,20,20
Color 0,0,0
Text a\x,a\y,Chr$(let)
If a\x>800 Or a\y>600 Or a\x<0
miss=miss+1
Delete a
Else
If tmp$=Lower$(Chr$(let)) Then score=score+10:Delete a

EndIf
Next

If Asc(tmp$)<>0 And score=oscore Then miss=miss+1
End Function
Function newlet()
a.enemy=New enemy
a\x#=Rnd(200,400)
a\xdir#=Rnd(-2,2)
a\ydir#=Rnd(0,2)
a\let=randletter()
a\col=Rnd(100,255) Shl 16 Or Rnd(100,255) Shl 8 Or Rnd(100,255)
End Function
Function randletter()
tmp=Rnd(55,90)
Return tmp
End Function
« Last Edit: July 21, 2007 by Shockwave »
I will bite you - http://s5.bitefight.se/c.php?uid=31059
Challenge Trophies Won:

Offline mike_g

  • Amiga 1200
  • ****
  • Posts: 435
  • Karma: 34
    • View Profile
Re: Blitz coding
« Reply #1 on: April 11, 2007 »
Heres my version of the first task. Took bang on 45 minutes. I ran out of time before I could sort the levels out so for now you can only get to level 4. Its got multiple letters, title, game over and stuff so i'm quite happy with it. With more time I might have made the letters bounce up and down.

Code: [Select]
AppTitle "Quick Draw"
Graphics 640, 480, 32, 2
SetBuffer BackBuffer()
SeedRnd MilliSecs()

Global state, hiscore, score, level=1, time=60
Global old_time=MilliSecs()
Type letter
Field x, y, char, spd
End Type



While Not KeyHit(1)
Cls
If state = 0 ;Title
Text 20, 20, "Letter Shootout"
Text 20, 40, "Hit space to begin"
Text 20, 60, "Hiscore: "+hiscore
WaitKey
state=1
Else If state = 1 ;Game
DrawBar()
CheckGen()
DrawLetters()
ShootLetters()
If MilliSecs() >= old_time+1000 Tick()
LevelUp()
Else ;Game Over
Text 20, 20, "Game over, your score: "+score
If score > hiscore Then hiscore = score
Text 20, 40, "Hiscore: "+hiscore
Text 20, 60, "Hit any key to continue"
WaitKey
state=0
score=0
time=60
level=1
EndIf
Flip
Wend

Function DrawBar()
Color 50, 50, 50
Rect 0, 0, 640, 20
Color 100, 100, 100
Text 10, 2, "Score: "
Text 260, 2, "Level: "
Text 440, 2, "Time: "
Color 180, 50, 50
Text 60, 2, score
Text 320, 2, level
Text 500, 2, time
End Function

Function CheckGen()
For l.letter = Each letter
num=num+1
Next
If num < level
l.letter = New letter
l\x= -10
l\y=Rand(20, 460)
l\spd=Rand(1, level)
l\char = Rand(48, 90)
While l\char > 57 And l\char < 97
l\char = Rand(48, 122)
Wend
EndIf
End Function

Function DrawLetters()
For l.letter = Each letter
l\x=l\x+l\spd
Color 80, 80, 80
Rect l\x-1, l\y, 10, 12

Color 255, 0, 0
  Text l\x, l\y, Chr$(l\char)
If l\x > 640
   score = score -2
   time = time-1
   Delete l.letter
EndIf
Next
End Function

Function ShootLetters()
in = GetKey()
For l.letter = Each letter
If l\char = in
Delete l.letter
score=score+10
EndIf
Next
End Function

Function Tick()
time = time - 1
If time <= 0 Then state=2
old_time=MilliSecs()
End Function

Function LevelUp()
If score >= 100 And level = 1
score = score + time
level = level+1
time = 80
Else If score >=500 And level =2
score = score + (time*2)
level = level+1
time = 100
Else If score >=1500 And level=3
score = score + (time*3)
level = level+1
time = 100
Else If score >=1500 And level=4
score = score + (time*3)
level = level+1
time = 150
EndIf
End Function