AA Mania Code

Share your advanced PureBasic knowledge/code with the community.
DriakTravo
Enthusiast
Enthusiast
Posts: 346
Joined: Fri Oct 10, 2003 12:42 am
Location: Tampa,FL,USA
Contact:

AA Mania Code

Post by DriakTravo »

Code updated For 5.20+

This is a game I started but never got close to finishing. I am throwing out my code to the public. Mabe it will help some people.... or mabe this is just a waste of a topic.... Well here it is anyway.

Code: Select all

InitSprite()
InitMouse()
InitKeyboard()
InitSound()

OpenScreen(800,600,32,"")

Structure bullet
  X.f
  Y.f
  XS.f
  YS.f
EndStructure

Global NewList bullets.bullet()

Procedure Addbullet(X.f,Y.f,XS.f,YS.f)
  AddElement(Bullets())
  Bullets()\X = X
  Bullets()\Y = Y
  Bullets()\XS = XS
  Bullets()\YS = YS
EndProcedure

Global mouseangle, BulletSpeed
BulletSpeed = 40

Global Dim star.bullet(201)
For X = 0 To 200
  Star(X)\X = Random(800)
  Star(X)\Y = Random(800)
Next X

Procedure SpaceBackGround()
  
  For x = 0 To 200
    Circle(Star(x)\X,Star(x)\Y,1,RGB(255,255,255))
  Next X
  
EndProcedure
Global PlayerX.f,PlayerY.f
PlayerX = 1
PlayerY = 599
Global PlayerX2.f,PlayerY2.f
PlayerX2 = 799
PlayerY2 = 599
Procedure.f GetMouseAngle()
  ExamineMouse()
  x1 = PlayerX
  y1 = PlayerY
  x2 = MouseX()
  y2 = MouseY()
  a.f = x2-x1
  b.f = y2-y1
  c.f = Sqr(a*a+b*b)
  winkel.f = ACos(a/c)*57.29577
  If y1 < y2 : winkel=360-winkel : EndIf
  ProcedureReturn winkel+90
EndProcedure
Procedure.f GetMouseAngle2()
  ExamineMouse()
  x1 = PlayerX2
  y1 = PlayerY2
  x2 = MouseX()
  y2 = MouseY()
  a.f = x2-x1
  b.f = y2-y1
  c.f = Sqr(a*a+b*b)
  winkel.f = ACos(a/c)*57.29577
  If y1 < y2 : winkel=360-winkel : EndIf
  ProcedureReturn winkel+90
EndProcedure
Addbullet(0,0,0,0)
Repeat
  ClearScreen(RGB(0,0,0))
  ExamineMouse()
  
  ResetList(Bullets())
  While NextElement(Bullets())
    StartDrawing(ScreenOutput())
    color = Random(150)+105
    Line(Bullets()\X,Bullets()\Y,Bullets()\XS,Bullets()\YS,RGB(color,color,0))
    StopDrawing()
    Bullets()\X + Bullets()\XS
    Bullets()\Y + Bullets()\YS
    If Bullets()\X > 800 + Bullets()\XS
      DeleteElement(Bullets())
    EndIf
    If Bullets()\X < 0 - Bullets()\XS
      DeleteElement(Bullets())
    EndIf
    If Bullets()\Y > 600 + Bullets()\YS
      DeleteElement(Bullets())
    EndIf
    If Bullets()\Y < 0 - Bullets()\YS
      DeleteElement(Bullets())
    EndIf
  Wend
  
  StartDrawing(ScreenOutput())
  SpaceBackGround()
  Line(MouseX()-3,MouseY()-6,6,0,RGB(255,255,0))
  Line(MouseX()-3,MouseY()+6,6,0,RGB(255,255,0))
  Line(MouseX()-6,MouseY()-3,0,6,RGB(255,255,0))
  Line(MouseX()+6,MouseY()-3,0,6,RGB(255,255,0))
  Plot(MouseX(),MouseY(),RGB(255,255,0))
  StopDrawing()
  
  If MouseButton(2) = 1
    End
  ElseIf MouseButton(1) = 1
    
    Angle.f = GetMouseAngle()+Random(4)-2
    SpeedX.f = Sin(Angle*(3.14/180))*Bulletspeed
    SpeedY.f = Cos(Angle*(3.14/180))*Bulletspeed
    dudecounter + 1
    If dudecounter = 19
      dudecounter = 0
      Addbullet(PlayerX,PlayerY,SpeedX,SpeedY)   
      soundcounter =0
      SetSoundFrequency(1,25050+(Random(5000)-2500))
      SoundVolume(1,20)
      PlaySound(1)
    EndIf
    Angle.f = GetMouseAngle2()+Random(4)-2
    SpeedX.f = Sin(Angle*(3.14/180))*Bulletspeed
    SpeedY.f = Cos(Angle*(3.14/180))*Bulletspeed
    dudecounter + 1
    If dudecounter = 5
      dudecounter = 0
      Addbullet(PlayerX2,PlayerY2,SpeedX,SpeedY)   
      soundcounter =0
      
    EndIf
  EndIf
  
  FlipBuffers()
  ExamineKeyboard()
ForEver
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2148
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Post by Andre »

Your codes would be more usable, when you also post the include file... :wink:
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
DriakTravo
Enthusiast
Enthusiast
Posts: 346
Joined: Fri Oct 10, 2003 12:42 am
Location: Tampa,FL,USA
Contact:

Post by DriakTravo »

oops... you can delete that part, it no longer uses that.
Post Reply