Steuerung

Übersicht BlitzBasic Beginners-Corner

Neue Antwort erstellen

 

Roggi

Betreff: Steuerung

BeitragFr, Okt 28, 2005 8:51
Antworten mit Zitat
Benutzer-Profile anzeigen
Ich habe ja mein Rennspiel gecodet und ich will das er wenn er über Sand fährt langsamer ist aber irgendwie ist er wenn ich über Sand fahre schneller geworden. Also genau umgedreht. Was mach ich falsch
BlitzBasic: [AUSKLAPPEN]
Graphics 1024,768,16,2 
SetBuffer BackBuffer()
start=LoadImage(\"Grafik\start.bmp\");Startbilschirm
DrawImage start,1,1
Delay 2500
Cls


SetFont(LoadFont(\"Comic Sans MS\",30,1))

Const game_pause = 1
Const game_menue = 2
Const game_haupt = 3
Const game_over = 4

Global game_zustand = game_menue


;Wichtig. Hauptschleife. Hier wird das ganze Spiel verwaltet.

Repeat


Select game_zustand
Case game_menue
GameMenue()
Case game_haupt
GameHaupt()
Case game_pause
GamePause()
End Select


Until game_zustand = game_over
End





Function GameMenue()

Local temp_zustand = game_zustand

FlushMouse()
FlushKeys()

Repeat
ClsColor 25,60,135
Cls

Color 255,255,255
Text GraphicsWidth()/4,100,\"Die Rennstrecke - Beta\"

Color 255,255,255
Text GraphicsWidth()/3,200,\"Spiel\"

Color 255,255,255
Text GraphicsWidth()/3,300,\"ENDE\"


If MouseHit(1)
If RectsOverlap(MouseX(),MouseY(),1,1,GraphicsWidth()/3,200,StringWidth(\"START\"),StringHeight(\"START\"))
game_zustand = game_haupt
ElseIf RectsOverlap(MouseX(),MouseY(),1,1,GraphicsWidth()/3,300,StringWidth(\"ENDE\"),StringHeight(\"ENDE\"))
game_zustand = game_over
EndIf
EndIf


If KeyHit(1)
End
EndIf

Flip
Until game_zustand<>temp_zustand

End Function


Function GameHaupt()
Graphics 800,600,32,1
SetBuffer BackBuffer()

links=203
rechts=205
hoch=200
runter=208


AppTitle (\"Die Autofahrt-Tom 10.05\");das was im Task steht


Auto=LoadImage(\"Grafik\Auto1.bmp\")
spielbild1 = LoadImage(\"Grafik\Map.bmp\")
Spielbild2=LoadImage(\"Grafik\Map2.bmp\")
ziel=LoadImage(\"Grafik\ziel.bmp\")
Runden =LoadImage(\"Grafik\Runden.bmp\")
Mauer=LoadImage(\"Grafik\Boxenmauer.bmp\")
Explosion=LoadImage(\"Grafik\Explosion.bmp\")
Sand=LoadImage(\"Grafik\Sand.bmp\")
xs# = 400; Wo das Auto steht
ys#= 450

xt=480
yt=400


Repeat
Cls

;------------------------- Bewegung des Spielers -----------------------
If KeyDown(hoch) And ys# > -2 Then ys# =ys#- 0.4
If KeyDown(runter) And ys# < 570 Then ys# =ys#+ 0.4
If KeyDown(rechts) And xs#< 770 Then xs#=xs#+ 0.4
If KeyDown(links) And xs# > -2 Then xs# =xs#- 0.4




TileBlock spielbild1, 0, 0

DrawImage Sand,1,20
MaskImage Sand,255,255,255
DrawImage Mauer,130,215
MaskImage Mauer,255,255,255
DrawImage Ziel, xt, yt
DrawImage Runden, 500,20
MaskImage Runden, 255,255,255
Color 0,0,0

DrawImage Auto,xs,ys
MaskImage Auto,255,255,255
If ImagesCollide (Auto,xs,ys,0,Sand,1,1,0)Then
If KeyDown(hoch) And ys#>-2 Then ys#=ys#- 0.1
If KeyDown(runter) And ys#<570 Then ys#=ys#+0.1
If KeyDown(rechts) And xs#<770Then xs#=xs#+ 0.1
If KeyDown(links) And xs#>-2 Then xs# =xs#-0.1
EndIf
If ImagesCollide (Auto,xs,ys,0,Mauer,150,220,0)Then
Delay 2500
ClsColor 255,225,100
Cls
Text 200,200,\"Jetzt hast du verloren\"
EndIf
Text 700, 40, Str$(Rundenzahl)
If ImagesOverlap (Auto,xs,ys,Ziel,xt,yt) Then
Rundenzahl=Rundenzahl +1
If Rundenzahl=245 Then
Rundenzahl=1
EndIf
EndIf
If Rundenzahl=10Then
Text 200,400,\"Du bist gerade 10 Runden gefahren\"


EndIf
Flip

Until KeyHit(1)
End




Local temp_zustand = game_zustand
Local x = GraphicsWidth()/2
Local y = GraphicsHeight()/2
Local h = 0

FlushKeys()
FlushMouse()

Repeat
ClsColor 200,200,200
Cls


If KeyHit(57)
game_zustand = game_pause
EndIf


If KeyHit(1)
game_zustand = game_menue
EndIf

Flip
Until game_zustand<>temp_zustand

End Function

Function GamePause()

Local temp_zustand = game_zustand

FlushKeys()
FlushMouse()

Repeat
ClsColor 255,0,0
Cls

Color 0,0,255
Text GraphicsWidth()/2,GraphicsHeight()/2,\"ICH BIN DIE PAUSE!!!\",1,1

If KeyHit(57)
game_zustand = game_haupt
EndIf

Flip
Until game_zustand<>temp_zustand

End Function

Klip

BeitragFr, Okt 28, 2005 10:37
Antworten mit Zitat
Benutzer-Profile anzeigen
Hm, dein Code ist etwas unübersichtlich, gewöhn dir doch an, ihn einzurücken und einen Kommentar zu setzen, wo genau die Stelle liegt, die dir Probleme macht.

Deine Steuerungslösung ist nicht so toll, finde ich.

BlitzBasic: [AUSKLAPPEN]

;Beispiel
speedx#:speedy# ; die beiden vars für das Tempo
speed_accel# = 0.2 ; Die Beschleunigung
max_speed# = 5 ; Die max. Endgeschwindigkeit

Repeat
Cls

Oval x,y,10,10 ; Auto malen

x = x + speedx ; x um speedx verschieben
y = y - speedy ; selbes mit y

If speedy < max_speed ; wenn Tempo < Max. Tempo
If KeyDown(hoch) Then speedy = speedy + speed_accel ; Tempo = Tempo + Beschleunigung
EndIf

Flip
Until KeyHit(1)
End

Neue Antwort erstellen


Übersicht BlitzBasic Beginners-Corner

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group