Here is the actual game if you want to download: http://www.freewebs.com/attotheriveronus/Game.zip Right click the link and save link as
The code is:
AppTitle "Game Test"
Const width=900,height=700
Graphics3D width,height,32,2
Global T = LoadTerrain("Terrain.png")
Ttex = LoadTexture("TerrainTex.jpg")
Global Panel = LoadImage("Panel.png")
Global goldicon = LoadImage("goldicon.png")
Global poticon = LoadImage("poticon.png")
Global deathsound = LoadSound("death.wav")
Global losesound = LoadSound("lose.wav")
Global zapsound = LoadSound("zap.wav")
Global lvlupsound = LoadSound("lvlup.wav")
Global hitsound = LoadSound("hit.wav")
Global goldsound = LoadSound("gold.wav")
ScaleTexture Ttex,256,256
EntityTexture T,Ttex
ScaleEntity T,2,100,2
Sky = CreateSphere(44)
ScaleEntity Sky,700,700,700
FlipMesh Sky
EntityColor Sky,180,180,245
;Setup Camera
Global Camera = CreateCamera()
CameraViewport Camera,0,0,width,height
CameraRange Camera,1,9000
;======================================
;Setup Player
;======================================
Type Player
Field model,hp,attack,maxhp,experience,nextlvl,lvl,maxattack,cooled,Current#,maxtime#
End Type
player.Player = New Player
player\lvl = 1
player\nextlvl = 100
player\experience = 0
player\model = CreateSphere(44)
EntityColor player\model,255,105,0
MoveEntity player\model,50,0,50
player\hp = 15
player\maxhp = 15
player\attack = 1
player\maxattack = 2
player\cooled = True
player\maxtime# = 3
player\current# = 3.0
;======================================
;Update Hostile
;======================================
Global IDLE,CONFRONT,DEAD,FLEE
IDLE = 1
CONFRONT = 2
DEAD = 3
FLEE = 4
Type Hostile
Field model,hp,attack,attackrange,state,target.player,ox,oz,fleepivot,cooled,Current#,maxtime#
End Type
Function CreateHostile.hostile(spec,x,z)
A.hostile = New hostile
Select spec
Case 1
A\model = CreateSphere(22)
A\hp = 5
A\attack = 2
A\attackrange = 20
A\state = IDLE
A\maxtime# = 5.0
A\cooled = True
A\current# = 0.0
End Select
A\ox = x
A\oz = z
A\fleepivot = CreatePivot()
PositionEntity A\fleepivot,x,TerrainY(t,x,0,z),z
PositionEntity A\model,x,0,z
Return A
End Function
Function UpdateHostile()
For A.hostile = Each hostile
A\current# = A\current# + 0.1
If A\maxtime# <= A\current#
A\cooled = True
A\current# = 0.0
EndIf
PositionEntity A\model,EntityX(A\model),3+TerrainY(T,EntityX(A\model),0,EntityZ(a\model)),EntityZ(A\model)
If A\hp < 1
A\state = DEAD
For P.player = Each player
P\experience = P\experience + 15
Next
EndIf
Select A\state
Case IDLE
For P.player = Each player
If EntityDistance(A\model,P\model) < A\attackrange And P\hp > 0
A\target.player = P
A\state = CONFRONT
EndIf
Next
Case CONFRONT
If EntityDistance(A\model,A\target\model) < 4
If A\cooled = True
A\target\hp = A\target\hp - A\attack
A\cooled = False
If A\target\hp < 1
A\state = flee
EndIf
EndIf
Else
PointEntity A\model,A\target\model
MoveEntity A\model,0,0,1
EndIf
If (Abs(EntityX(A\model) + EntityZ(A\model)- A\ox-A\oz)) > 120
A\state = FLEE
EndIf
Case DEAD
Display("Gray Ball has died.",500,35,255,0,0,5)
PlaySound deathsound
CreateItem(Rand(1,2),EntityX(A\model),EntityZ(A\model))
FreeEntity A\model
Delete A
Case FLEE
PointEntity A\model,A\fleepivot
MoveEntity A\model,0,0,1
If EntityDistance(A\model,A\fleepivot) < 3
A\state = IDLE
EndIf
End Select
Next
End Function
;======================================
;Setup Items
;======================================
Type Item
Field model,increase$,amount,spec,used,name$,tooltip$,icon,inv
End Type
Function CreateItem.Item(spec,x,z)
A.Item = New Item
A\spec = spec
A\used = False
Select spec
Case 1
A\model = CreateCone()
EntityColor A\model,255,0,0
A\increase$ = "health"
A\amount = 5
A\icon = poticon
A\name$ = "Potion I"
A\tooltip$ = "Heals for 5 health."
Case 2
A\model = CreateCylinder()
EntityColor A\model,205,160,0
ScaleEntity A\model,1,.01,1
RotateEntity A\model,90,0,0
A\increase$ = "gold"
A\amount = Rand(1,4)
A\icon = goldicon
A\name$ = "Gold coins"
A\tooltip$ = A\amount + " gold coins."
End Select
PositionEntity A\model,x,3+TerrainY(T,x,0,z),z
EntityShininess A\model,1
A\inv = False
Return A
End Function
Function UpdateItem()
For A.Item = Each Item
If A\inv = False
For P.player = Each player
If EntityDistance(P\model,A\model) < 2
PickUpItem(A)
EndIf
Next
EndIf
Next
.skip
End Function
;======================================
Global RESETR = False
Global GOLD = 0
Global INVENTORYITEMS = 0
Dim inventory(9)
For A = 1 To 9
Inventory(A) = False
Next
SeedRnd MilliSecs()
.reset
CreateHostile(1,25,25)
CreateItem(1,50,25)
CreateItem(1,25,50)
For X = 1 To 25
CreateHostile(1,65+Rand(0,200),65+(Rand(0,200)))
Next
;======================================
;======================================
;======================================
;======================================
;======================================
;======================================
;======================================
While Not KeyDown(1)
Cls
If RESETR = True
RESETR = False
Goto reset
EndIf
UpdateCamera(Camera,player\model)
UpdateHostile()
UpdateItem()
UpdatePlayer()
If MouseHit(1)
DebugLog MouseX() + "," + MouseY()
EndIf
UpdateWorld
RenderWorld
UpdateText()
Color 0,0,0
Rect 495,32,150,15
Color 100,100,100
Rect 500,35,150,13
Color 0,0,0
Rect 24,24,102,7
Color 255,0,0
Rect 25,25,player\hp*(100.0/player\maxhp),5
Text 25,10,"Health"
Text 25,55,"Press A while next to an enemy (gray ball) to attack."
Text 25,65,"The red cones restore health."
DrawImage Panel,750,0
UpdateInventory()
Text 807,418,GOLD
Color 0,0,0
Rect 0,100,150,500
Color 255,0,0
Text 5,100," Level " + player\lvl
Text 5,115,"HP: " + player\hp + "/" + player\maxhp
Text 5,130,"Dmg: " + player\attack + " - " + player\maxattack
Text 5,150,"Exp: " + player\experience + "/" + player\nextlvl
Flip
Wend
End
;======================================
;======================================
;======================================
;======================================
;======================================
;======================================
Function UpdateCamera(cam,pID)
If KeyDown(200)
MoveEntity pID,0,0,0.45
EndIf
If KeyDown(203)
TurnEntity pID,0,1,0
EndIf
If KeyDown(208)
MoveEntity pID,0,0,-0.45
EndIf
If KeyDown(205)
TurnEntity pID,0,-1,0
EndIf
PositionEntity pID,EntityX(pID),3+TerrainY(T,EntityX(pID),0,EntityZ(pID)),EntityZ(pID)
PositionEntity cam,EntityX(pID),EntityY(pID),EntityZ(pID)
RotateEntity cam,EntityRoll(pID),EntityYaw(pID),EntityPitch(pID)
MoveEntity cam,0,8,-16
End Function
;================================================
;================================================
;================================================
Function UpdatePlayer()
For P.player = Each player
P\current# = P\current# + 0.1
If P\maxtime# <= P\current#
P\cooled = True
P\current# = 0.0
EndIf
If P\hp > P\maxhp
P\hp = P\maxhp
EndIf
If P\hp < 1
For A.Item = Each Item
If A\inv = False
FreeEntity A\model
EndIf
Delete A
Next
For H.hostile = Each hostile
FreeEntity H\model
Delete H
Next
For I.icon = Each icon
Delete I
Next
INVENTORYITEMS = 0
RESETR = True
Cls
Flip
Color 255,0,0
Text 200,200,"You have died!"
PlaySound losesound
Flip
Delay(500)
Text 200,250,"Reloading the game.."
Flip
P\hp = P\maxhp
PositionEntity P\model,50,0,50
RotateEntity P\model,0,0,0
Delay(2000)
EndIf
If KeyHit(30)
For H.hostile = Each hostile
If EntityDistance(H\model,P\model) < 5 And P\cooled = True
PlaySound hitsound
P\cooled = False
H\hp = H\hp - Rand(P\attack,P\maxattack)
EndIf
Next
EndIf
If P\experience >= P\nextlvl
LevelUpPlayer(P)
EndIf
Next
End Function
Function LevelUpPlayer(p.player)
Display("Level up!.",500,35,255,0,0,5)
PlaySound lvlupsound
p\nextlvl = p\nextlvl + (30*p\lvl)
p\maxhp = p\maxhp + (5*p\lvl)
p\attack = p\attack + 1
p\maxattack = p\maxattack + 1
p\lvl = p\lvl + 1
p\experience = 0
End Function
;================================================
;Text Display
;================================================
Type DisplayText
Field x,y,r,g,b,tex$,current#,max#
End Type
Function Display.DisplayText(tex$,x,y,r,g,b,time#)
Te.DisplayText = New DisplayText
Te\x = x
Te\y = y
Te\r = r
Te\g = g
Te\b = b
Te\current# = 0.0
Te\max# = time#
Te\tex$ = tex$
Return Te
End Function
Function UpdateText()
For Te.DisplayText = Each DisplayText
Te\current# = Te\current# + .1
R = ColorRed()
G = ColorGreen()
B = ColorBlue()
Color Te\r,Te\g,Te\b
Text Te\x,Te\y,Te\tex$
Color R,G,B
If Te\current# >= Te\max#
Delete Te
EndIf
Next
End Function
;=================================================
;Inventory
;=================================================
Type icon
Field I.item,slot,img,x,y,name$
End Type
Function MouseOverIcon(I.icon)
If MouseX() > I\x And MouseY() > I\y
If MouseX() < I\x + 50 And MouseY() < I\y + 50
Return True
Else
Return False
EndIf
EndIf
End Function
Function UpdateInventory()
For A.icon = Each icon
DrawImage A\img,A\x,A\y
If MouseOverIcon(A)
Text 763,465,A\I\name$
Text 763,480,A\I\tooltip$
EndIf
Next
If MouseHit(1)
For A.icon = Each icon
If MouseOverIcon(A)
UseItem(slot)
EndIf
Next
EndIf
End Function
Function PickupItem(A.item)
If INVENTORYITEMS < 9
C.icon = New icon
C\I = A
C\I\inv = True
FreeEntity C\I\model
C\slot = INVENTORYITEMS + 1
C\img = C\I\icon
C\name$ = C\I\name$
C\x = GetIconX(C\slot)
C\y = GetIconY(C\slot)
INVENTORYITEMS = INVENTORYITEMS + 1
EndIf
End Function
Function UseItem(slot)
For C.icon = Each icon
If MouseOverIcon(C)
Select C\name$
Case "Gold coins"
GOLD = GOLD + C\I\amount
Case "Potion I"
For P.player = Each player
P\hp = P\hp + C\I\amount
Next
End Select
Delete C\I
Delete C
INVENTORYITEMS = INVENTORYITEMS - 1
EndIf
Next
End Function
Function GetIconX(slot)
Select Slot
Case 1
Return 759
Case 2
Return 813
Case 3
Return 864
Case 4
Return 759
Case 5
Return 811
Case 6
Return 863
Case 7
Return 758
Case 8
Return 809
Case 9
Return 858
End Select
End Function
Function GetIconY(slot)
Select Slot
Case 1
Return 549
Case 2
Return 549
Case 3
Return 549
Case 4
Return 599
Case 5
Return 599
Case 6
Return 599
Case 7
Return 649
Case 8
Return 649
Case 9
Return 649
End Select
End Function
My code is mostly functional right now.. but does anyone have any suggestions or have any changes I should make in the code, thanks.
|