Newsletter 17: mini-Spiel

Übersicht BlitzBasic Allgemein

Neue Antwort erstellen

D2006

Administrator

Betreff: Newsletter 17: mini-Spiel

BeitragDi, Apr 05, 2005 17:39
Antworten mit Zitat
Benutzer-Profile anzeigen
Hey Leute,

folgender Code ist nicht von mir, sondern aus dem aktuellen Newsletter.
Dachte mir, dass sie es wert sind, hier gepostet zu werden.
(Wenn jemand anders denkt und Mod Status hat, kann er das ganze ja löschen.)

Also ein kleines Game:
Man muss mit dem Cube den anderen Cube ausweichen, dabei aber so weit wie möglich vorankommen. 100% sollen wohl unmöglich sein.

BLITZ 3D
Code: [AUSKLAPPEN]
;ARROW KEYS TO MOVE
;LEFT CONTROL TO JUMP
Global rndseed2

Type thing
   Field entity
   Field pivot
   Field speedx#,speedz#,speedy#
   Field accel#
   Field speedmax#
   Field fric#
   Field w#,h#
   Field trailentity[19]
End Type

Type globals
   Field screenw,screenh
   Field camera
   Field you.thing
   Field room
   Field roomw
   Field roomh
   Field score
   Field scorehigh
   Field grav#
   Field thtrails
   Field file
   Field replaying
   Field fileline$
   Field filelinei
End Type
Global gl.globals=New globals

gl_setup()
room_setup()
ths_setup()
camera_setup()

mainloop()

Function l___________GAME()
End Function


Function mainloop()
   timer=CreateTimer(35)
   
   Repeat
      WaitTimer timer
      
      If ths_update() Then
         reset()
      EndIf
      camera_update()
   
      RenderWorld
      twoddraw()
      Flip
      
   Forever
   
End Function

Function twoddraw()
   gl\score=EntityZ(gl\you\pivot)+gl\roomh
   If gl\score>gl\scorehigh Then gl\scorehigh=gl\score
   Color 255,255,255
   Text 0,0,gl\score+" / "+gl\roomh*2+"="+gl\score*100/(gl\roomh*2)+"%"
   Text 0,15,"Best: "+gl\scorehigh+"="+gl\scorehigh*100/(gl\roomh*2)+"%"
End Function

Function reset()
   Local th.thing
   
   
   l=0
   camera_update()
   Repeat
      l=l+1
      If l>100 Then Exit
      TranslateEntity gl\camera,Sin(l*2.5)*(l/50.0),-.3,-(l/50.0)
      PointEntity gl\camera,gl\you\pivot
      RenderWorld
      twoddraw()
      Flip
   Forever
   FlushKeys
   WaitKey
   If KeyHit(1) Then finish()
   
   If gl\replaying=0 Then
      CloseFile gl\file
      gl\file=WriteFile("replay.txt")
      seed=MilliSecs()
      SeedRnd2 seed
      WriteLine gl\file,seed
      gl\fileline=""
   EndIf
   
   For th=Each thing
      th_kill(th)
   Next
   ths_setup()
   camera_setup()
End Function


Function finish()
   If gl\replaying=0 Then WriteLine gl\file,gl\fileline
   CloseFile gl\file
   End
End Function


Function l___________GLOBALS()
End Function



Function gl_setup()

   gl\screenw=800
   gl\screenh=600
   Graphics3D gl\screenw,gl\screenh,0,1

   
   gl\camera=CreateCamera()
   CreateLight()
   
   gl\grav=.44
   
   gl\thtrails=4
   
   ;gl\replaying=1
   If FileType("replay.txt")=1 Then gl\replaying=Input("choose: 1=replay 0=play : ")
   If gl\replaying<>1 Then gl\replaying=0
   
   SetBuffer BackBuffer()

   If gl\replaying Then
      gl\file=ReadFile("replay.txt")
      SeedRnd2 ReadLine(gl\file)
      gl\fileline=ReadLine(gl\file)
      gl\filelinei=1
   Else
      gl\file=WriteFile("replay.txt")
      seed=MilliSecs()
      SeedRnd2 seed
      WriteLine gl\file,seed
   EndIf
End Function


Function room_setup()
   gl\roomw=200
   gl\roomh=660

   gl\room=CreateCube()
   ScaleEntity gl\room,-gl\roomw,-500,-gl\roomh
   roomtex=CreateTexture(32,32)
   SetBuffer TextureBuffer(roomtex)
   Color 255,0,0
   Oval 0,0,32,32
   SetBuffer BackBuffer()
   ScaleTexture roomtex,.02,.02
   EntityTexture gl\room,roomtex
   PositionEntity gl\room,0,500,0
   
   EntityPickMode gl\room,2
End Function




Function camera_setup()
   RotateEntity gl\camera,90,0,0
End Function

Function camera_update()
   PositionEntity gl\camera,EntityX(gl\you\pivot),130,EntityZ(gl\you\pivot)-30
   PointEntity gl\camera,gl\you\pivot
End Function

Function l___________THINGS()
End Function

Function th_kill(th.thing)
   For ft=1 To gl\thtrails
      FreeEntity th\trailentity[ft]
   Next
   FreeEntity th\entity
   FreeEntity th\pivot
   Delete th
End Function
Function ths_setup()
   Local th.thing
   
   For f=1 To 106
      th=New thing
      th\pivot=CreatePivot()
      th\entity=CreateCube(th\pivot)
      x=Rnd2(-gl\roomw,+gl\roomw)
      z=Rnd2(-(gl\roomh-50),+gl\roomh)
      If f>1 Then
         th\speedmax=2
         th\accel=.01
         th\fric=.0001
         PositionEntity th\pivot,x,0,z
         th\w=2
         th\h=3
         ScaleEntity th\entity,th\w,(th\w+th\h)/2,th\h
         EntityColor th\entity,0,Rnd2(111,255),Rnd2(111,255)
      Else
         PositionEntity th\pivot,0,th\h,-(gl\roomh-10)
         EntityColor th\entity,100,200,0
         th\w=3
         th\h=3
         ScaleEntity th\entity,th\w,3,th\h
         th\speedmax=1
         th\accel=1
         th\fric=1
      EndIf
      
      
      For ft=1 To gl\thtrails
         th\trailentity[ft]=CopyEntity(th\entity)
         EntityAlpha th\trailentity[ft],1-Float(ft)/gl\thtrails
      Next
   Next
   
   gl\you=First thing
End Function


Function ths_update()
   Local th.thing

   For th=Each thing
      For ft=gl\thtrails To 2 Step -1
         PositionEntity th\trailentity[ft],EntityX(th\trailentity[ft-1]),EntityY(th\trailentity[ft-1]),EntityZ(th\trailentity[ft-1])
      Next
      PositionEntity th\trailentity[1],EntityX(th\pivot),EntityY(th\pivot),EntityZ(th\pivot)

      If th<>gl\you Then
         th_ai(th)
      Else
         th_controls(th)
      EndIf
      
      If EntityX(th\pivot)+th\speedx<-gl\roomw Then th\speedx=-th\speedx
      If EntityX(th\pivot)+th\speedx>+gl\roomw Then th\speedx=-th\speedx
      If EntityZ(th\pivot)+th\speedz<-gl\roomh Then th\speedz=-th\speedz
      If EntityZ(th\pivot)+th\speedz>+gl\roomh Then th\speedz=-th\speedz
      If EntityY(th\pivot)<th\h Then
         PositionEntity th\pivot,EntityX(th\pivot),th\h,EntityZ(th\pivot)
         th\speedy=0
      EndIf
      MoveEntity th\pivot,th\speedx,th\speedy,th\speedz
      If EntityY(th\pivot)=th\h Then
         th\speedx=moveto(th\speedx,0,th\fric)
         th\speedz=moveto(th\speedz,0,th\fric)
      EndIf
      If EntityY(th\pivot)>th\h Then th\speedy=th\speedy-gl\grav
      If th<>gl\you Then
         If Abs(EntityY(th\pivot)-EntityY(gl\you\pivot)) < th\h+gl\you\h Then
            If RectsOverlap(EntityX(th\pivot)-th\w,EntityZ(th\pivot)-th\h,th\w*2,th\h*2, EntityX(gl\you\pivot)-gl\you\w,EntityZ(gl\you\pivot)-gl\you\h,gl\you\w*2,gl\you\h*2) Then
               Return 1
            EndIf
         EndIf
      EndIf
      
   Next
   If EntityZ(gl\you\pivot)>+gl\roomh-(gl\you\h+1) Then
      finish()
   EndIf
   
End Function

Function th_ai(th.thing)
   th\speedx=keep(th\speedx+Sgn(EntityX(gl\you\pivot)-EntityX(th\pivot))*th\accel,-th\speedmax,+th\speedmax)
   th\speedz=keep(th\speedz+Sgn(EntityZ(gl\you\pivot)-EntityZ(th\pivot))*th\accel,-th\speedmax,+th\speedmax)
End Function



Function th_controls(th.thing)
   Local l,r,u,d,j
   Local number
   

   If EntityY(gl\you\pivot)=th\h Then
      If gl\replaying Then
         number=Asc(Mid(gl\fileline,gl\filelinei,1))-Asc("a")
         ;DebugLog Mid(gl\fileline,gl\filelinei,1)
         gl\filelinei=gl\filelinei+1
         If gl\filelinei>Len(gl\fileline) Then
            If Eof(gl\file) Then WaitKey:End
            gl\filelinei=1
            gl\fileline=ReadLine(gl\file)
         EndIf
         d=number And %00001
         l=number And %00010
         u=number And %00100
         r=number And %01000
         j=number And %10000
      Else
         l=KeyDown(203)
         r=KeyDown(205)
         u=KeyDown(200)
         d=KeyDown(208)
         j=(KeyHit(29) Or KeyHit(56))
         number=d+(l Shl 1)+(u Shl 2)+(r Shl 3)+(j Shl 4)
         gl\fileline=gl\fileline+Chr(Asc("a")+number)
         If Len(gl\fileline)=50 Then
            WriteLine gl\file,gl\fileline
            gl\fileline=""
         EndIf
      EndIf
      If l Then th\speedx=keep(th\speedx-th\accel,-th\speedmax,+th\speedmax)
      If r Then th\speedx=keep(th\speedx+th\accel,-th\speedmax,+th\speedmax)
      If d Then th\speedz=keep(th\speedz-th\accel,-th\speedmax,+th\speedmax)
      If u Then th\speedz=keep(th\speedz+th\accel,-th\speedmax,+th\speedmax)
      If j Then
         If EntityY(th\pivot)=th\h Then
            th\speedy=5
         EndIf
      EndIf
   EndIf

   ;CameraPick gl\camera,mouse\x,mouse\y
   ;angleto(EntityX(th\pivot),EntityZ(th\pivot),PickedX(),PickedZ())
   
   If KeyHit(1) Then
      finish()
   EndIf
End Function

Function l___________NUMBER()
End Function

Function Keep#(num#,min#,max#)
   If num<min Then
      Return min
   ElseIf num>max
      Return max
   Else
      Return num
   EndIf
End Function


Function MoveTo#(num#,dest#=0,speed#=.01,away=0)
   If away=0 Then
      If Abs(dest-num)<speed Then Return dest
      If num<dest Then
         Return num+speed
      Else
         Return num-speed
      EndIf
   Else
      If num<dest Then
         Return num-speed
      Else
         Return num+speed
      EndIf
   EndIf
End Function

Function SeedRnd2(seed)
   rndseed2=seed
End Function

Function Rnd2#(min#,max#)
   rndseed2=(rndseed2+3) Mod 500
   Return ((rndseed2*Pi*Cos(rndseed2*(rndseed2 And 5)) + (100-rndseed2)^2 + Sqr(rndseed2 Or 12) + (rndseed2 Mod 15)/15.0 ) Mod (max-min)) + min
End Function




...

EDIT:
Hab den Aprilscherz mal rausgenomen.
Des weiteren schieb ich die lange Ladezeit mal auf die [ syntax]-Tags. Die machen beim parsen einer großen Anzahl von Befehlen wohl ne Kaffeepause zwischendrin. Müssen also die [ code]-Tags wieder her...

MfG
D2006
  • Zuletzt bearbeitet von D2006 am Di, Apr 05, 2005 19:10, insgesamt einmal bearbeitet

sbrog

BeitragDi, Apr 05, 2005 18:03
Antworten mit Zitat
Benutzer-Profile anzeigen
Lol auf das untere bin ich zuerst ganz schön reingefallen^^
 

OJay

BeitragDi, Apr 05, 2005 18:19
Antworten mit Zitat
Benutzer-Profile anzeigen
also sorry dee., aber das 2te ist:
1. schon veraltet (1. april) und
2. leider keine verarsche hier im forum, weil codes nicht in einer textarea dargestellt werden und man somit den trick sofort sieht Wink

D2006

Administrator

BeitragDi, Apr 05, 2005 18:30
Antworten mit Zitat
Benutzer-Profile anzeigen
Ja ne is klar.

Wollte auch nur den ersten posten, aber der zweite ... naja egal.
Das Spielchen ist trotzdem lustig...

btw: lädt dieser Thread bei euch auch so verdammt lang?

MfG

diGGa

GruppenKaspar

BeitragDi, Apr 05, 2005 18:45
Antworten mit Zitat
Benutzer-Profile anzeigen
ja läd auch so lang... kanns sein das im code n bug is?

Function">End Function

habs kurz gespielt. mein bestes is 48%
Gestern Nacht Schlug der Regen an mein Fenster
Ich ging durch das dunkle Zimmer und
glaubte im Licht der Straßenlampe
Den Geist unseres jahrhunderts auf der
Straße zu sehen
Der uns sagte, daß wir alle am Rande
des Abgrunds stehen.
- Al Steward


Athlon 64 3000+ / Radeon 9600 / 1024mb ddram

frigi

BeitragDi, Apr 05, 2005 18:51
Antworten mit Zitat
Benutzer-Profile anzeigen
ja, das is wohl wirklich ein kleiner fehler, aber 48% ist schon zu toppen...
3. versuch: 77% (einfach an der Wand entlang und hoffen^^)

diGGa

GruppenKaspar

BeitragDi, Apr 05, 2005 19:00
Antworten mit Zitat
Benutzer-Profile anzeigen
hab ja nur 5x probiert und nie gesagt das es pro is xD
Gestern Nacht Schlug der Regen an mein Fenster
Ich ging durch das dunkle Zimmer und
glaubte im Licht der Straßenlampe
Den Geist unseres jahrhunderts auf der
Straße zu sehen
Der uns sagte, daß wir alle am Rande
des Abgrunds stehen.
- Al Steward


Athlon 64 3000+ / Radeon 9600 / 1024mb ddram
 

NetPad

BeitragDi, Apr 05, 2005 19:41
Antworten mit Zitat
Benutzer-Profile anzeigen
hab 92%!

grs NP
User posted image
CCC:http://www.ccc.de/campaigns/music/
//aufmerksam gemacht von gameworx
 

NetPad

BeitragDi, Apr 05, 2005 19:57
Antworten mit Zitat
Benutzer-Profile anzeigen
Crying or Very sad billig!!!
das spiel beendet einfach so bei 100%!!!!

ist relativ einfach auf 100% zu kommen und keinesfalls unmöglich. einfach ein programm schreiben, das den cpu zur genüge auslastet. so läuft das ganze in slowmotion. Very Happy

billiger trick für billiges erfolgserlebnis.

grs NP
User posted image
CCC:http://www.ccc.de/campaigns/music/
//aufmerksam gemacht von gameworx

Suco-X

Betreff: .......

BeitragDi, Apr 05, 2005 22:41
Antworten mit Zitat
Benutzer-Profile anzeigen
Habe auch 100 % geschafft. Ohne Tricks. Man muss nur ab und zu zurückweichen und die ankommenden Cubes bisschen umgehen. Mit etwas Glück kommt man dann einfach auf 100%.
Ist ein Lustiges Game.
Mfg Suco
Intel Core 2 Quad Q8300, 4× 2500 MHz, 4096 MB DDR2-Ram, GeForce 9600GT 512 MB

Neue Antwort erstellen


Übersicht BlitzBasic Allgemein

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group