Game
Blitz3D Forums/Blitz3D Programming/Game
| ||
Why does this not work? What happens is, the main menu loads, then when I click it starts but for some reason a different screen is loaded. And the game doesnt seem to be functioning at all. I know this is incomplete so no comments about that What im not sure of is why the castle isnt being rendered and why the cannon isnt and why the attackers arent there. Entire Source: http://www.freewebs.com/attotheriveronus/CastleDefence.zip Graphics 900,700,32,2 Global Castle = LoadImage("Castle.jpg") Global Cannon = LoadImage("Cannon.jpg") Global CannonBall = LoadImage("CannonBall.jpg") Global Arrow = LoadImage("Arrow.jpg") Global Knight = LoadImage("Knight.jpg") Global Rammer = LoadImage("Rammer.jpg") Global GameMenu = LoadImage("Menu1.jpg") Global NextLevelMenu = LoadImage("LevelMenu.jpg") MaskImage Castle,255,0,0 MaskImage Cannon,255,0,0 MaskImage CannonBall,255,0,0 MaskImage Arrow,255,0,0 MaskImage Knight,255,0,0 MaskImage Rammer,255,0,0 Type Attacker Field vx#,img,hp,typeA,x,y End Type Type Projectile Field dmg,typeP,img,xv#,yv#,dist,x,y End Type Global CANNONS = 10 Global ARROWS = 25 Global Lives = 10 Global Angle = 0 Global Attackers = 0 Global Level = 1 Global MaxA = 0 Global KILLS = 0 Global GAME_MODE = 2 Global NotLoaded = False While Not KeyHit(1) Cls If NotLoaded = False CANNONS = 10 ARROWS = 25 Lives = 10 Angle = 0 Attackers = 0 Level = 1 MaxA = 0 KILLS = 0 GAME_MODE = 2 NotLoaded = True EndIf Select GAME_MODE Case 1 DrawScenery() AimControl() FireControl() UpdateAttackers() UpdateLevel() UpdateProjectiles() Case 2 UpdateMenu() ; Case 3 ; UpdateShopMenu() End Select Flip Wend Function StartNewGame() GAME_MODE = 1 End Function Function DrawScenery() DrawImage Castle,0,500 DrawImage Cannon,200,500 End Function Function UpdateMenu() DrawImage GameMenu,0,0 If MouseHit(1) And (MouseX() > 0 And MouseX() < 900) If MouseY() > 0 And MouseY() < 700 Cls StartNewGame() EndIf EndIf End Function Function AimControl() If KeyDown(200) Angle = Angle + 2 EndIf If KeyDown(208) Angle = Angle - 2 EndIf End Function Function UpdateProjectiles() For PX.projectile = Each projectile PX\dist = PX\dist + 1 PX\y = PX\y + PX\yv# PX\x = PX\x + PX\xv# For A.attacker = Each attacker If ProjectileCollide(PX,A) A\hp = A\hp - PX\dmg FreeImage PX\img Delete PX EndIf Next Next End Function Function UpdateAttackers() If Attackers < 3 A.attacker = New attacker A\typeA = Rand(0,1) Select A\typeA Case 0 A\img = Knight A\hp = 2 A\vx = -3 Case 1 A\img = Rammer A\hp = 5 A\vx = -2 End Select For B.Attacker = Each Attacker B\x = B\x + B\vx If B\hp < 1 FreeImage B\img Delete B KILLS = KILLS + 1 EndIf Next EndIf End Function Function UpdateLevel() MaxA = ((Level + 2)^2) * (2/3) If Lives < 0 GameOverScreen() GAME_MODE = 2 Cannons = 10 Arrows = 25 Lives = 10 Angle = 0 Attackers = 0 Level = 1 EndIf If Kills >= MaxA ShowLevelScreen(Level+1) Level = Level + 1 Kills = 0 Cannons = Cannons + Level Arrows = Arrows + (3/2) * Level Delay(3000) GameMode = 1 EndIf End Function Function GameOverScreen() Cls HSData = OpenFile("HighScores.dat") A$ = Input("Name: ") WriteInt(HSData,Kills) WriteString(HSData,A$) CloseFile HSData Kills = 0 End Function Function FireControl() If KeyHit(Asc("A")) If Arrows < 1 Goto Ending EndIf A.Projectile = New Projectile A\dmg = 1 A\img = Arrow A\typeP = 1 A\xv# = GetXV#(Angle) A\yv# = GetYV#(Angle) A\x = 200 A\y = 400 .Ending EndIf If KeyHit(Asc("B")) If Cannons < 1 Goto Ending2 EndIf A.Projectile = New Projectile A\dmg = 3 A\img = CannonBall A\typeP = 2 A\xv# = GetXV#(Angle) A\yv# = GetYV#(Angle) A\x = 200 A\y = 400 .Ending2 EndIf End Function Function ProjectileCollide(PR.Projectile,AT.attacker) If ImagesOverlap(PR\img,PR\X,PR\Y,AT\img,AT\X,AT\Y) Return True EndIf End Function Function ShowLevelScreen(levelX) DrawImage NextLevelMenu,0,0 Text "Level " + Level,450,350 End Function Function GetXV#(ang#) Return Cos#(ang#) End Function Function GETYV#(ang#) Return Sin#(ang#) End Function |
| ||
That link is interesting - when I click it it opens a copy of this thread. |
| ||
I think the webspace provider doesn't allow directlinking, and if you try it neverless, it will redirect you to the referrer, that's where you came from, from here. Try to use the RMB - save as... Zach: use the CODE tags for sourcecode: (code)...(/code), replace () by []. |
| ||
Zach : it seems you mistyped "gamemode" in the function UpdateLevel(), should it be "Game_Mode" ? |
| ||
Try eliminating the *(2/3) first line in the UpdateLevel() function replace the line with: MaxA = ((Level + 2)^2) Since the expression is an integer (2/3) doesn't return 0.66 but returns zero instead |
| ||
Ok but now I have a problem.. It is extremely laggy after i start rotating the Cannon Heres new code: Graphics 900,700,32,2 Include "Timers.bb" ;Ignore this I didnt even use it yet Global Castle = LoadImage("Castle.jpg") Global Cannon = LoadImage("Cannon.jpg") Global CannonBall = LoadImage("CannonBall.jpg") Global Arrow = LoadImage("Arrow.jpg") Global Knight = LoadImage("Knight.jpg") Global Rammer = LoadImage("Rammer.jpg") Global GameMenu = LoadImage("Menu1.jpg") Global NextLevelMenu = LoadImage("LevelMenu.jpg") MaskImage Castle,255,0,0 MaskImage Cannon,255,0,0 MaskImage CannonBall,255,0,0 MaskImage Arrow,255,0,0 MaskImage Knight,255,0,0 MaskImage Rammer,255,0,0 Type Attacker Field vx#,img,hp,typeA,x,y End Type Type Projectile Field dmg,typeP,img,xv#,yv#,dist,x,y End Type Global CANNONS = 10 Global ARROWS = 25 Global Lives = 10 Global Angle = 0 Global Attackers = 0 Global Level = 1 Global MaxA = 0 Global KILLS = 0 Global GAME_MODE = 2 Global NotLoaded = False While Not KeyHit(1) Cls If NotLoaded = False CANNONS = 10 ARROWS = 25 Lives = 10 Angle = 0 Attackers = 0 Level = 1 MaxA = 0 KILLS = 0 GAME_MODE = 2 NotLoaded = True EndIf Select GAME_MODE Case 1 DrawScenery() AimControl() FireControl() UpdateAttackers() UpdateLevel() UpdateProjectiles() Case 2 UpdateMenu() ; Case 3 ; UpdateShopMenu() End Select Flip Wend Function StartNewGame() GAME_MODE = 1 End Function Function DrawScenery() DrawImage Castle,0,500 DrawImage Cannon,200,500 For A.projectile = Each projectile DrawImage A\img,A\x,A\y Next For B.attacker = Each attacker DrawImage B\img,B\x,B\y Next End Function Function UpdateMenu() DrawImage GameMenu,0,0 If MouseHit(1) And (MouseX() > 0 And MouseX() < 900) If MouseY() > 0 And MouseY() < 700 Cls StartNewGame() EndIf EndIf End Function Function AimControl() If KeyDown(200) Angle = Angle + 2 EndIf If KeyDown(208) Angle = Angle - 2 EndIf RotateImage Cannon,Angle End Function Function UpdateProjectiles() For PX.projectile = Each projectile PX\dist = PX\dist + 1 PX\y = PX\y + PX\yv# PX\x = PX\x + PX\xv# For A.attacker = Each attacker If ProjectileCollide(PX,A) A\hp = A\hp - PX\dmg FreeImage PX\img Delete PX EndIf Next Next End Function Function UpdateAttackers() If Attackers < 3 A.attacker = New attacker A\typeA = Rand(0,1) Attackers = Attackers + 1 Select A\typeA Case 0 A\img = CopyImage(Knight) A\hp = 2 A\vx = -3 Case 1 A\img = CopyImage(Rammer) A\hp = 5 A\vx = -2 End Select For B.Attacker = Each Attacker B\x = B\x + B\vx If B\hp < 1 FreeImage B\img Delete B KILLS = KILLS + 1 EndIf Next EndIf End Function Function UpdateLevel() MaxA = ((Level + 2)^2) If Lives < 0 GameOverScreen() GAME_MODE = 2 Cannons = 10 Arrows = 25 Lives = 10 Angle = 0 Attackers = 0 Level = 1 EndIf If Kills >= MaxA ShowLevelScreen(Level+1) Level = Level + 1 Kills = 0 Cannons = Cannons + Level Arrows = Arrows + (3/2) * Level Delay(3000) Game_Mode = 1 EndIf End Function Function GameOverScreen() Cls HSData = OpenFile("HighScores.dat") A$ = Input("Name: ") WriteInt(HSData,Kills) WriteString(HSData,A$) CloseFile HSData Kills = 0 End Function Function FireControl() If KeyHit(Asc("A")) If Arrows < 1 Goto Ending EndIf A.Projectile = New Projectile A\dmg = 1 A\img = CopyImage(Arrow) A\typeP = 1 A\xv# = GetXV#(Angle) A\yv# = GetYV#(Angle) A\x = 200 A\y = 400 .Ending EndIf If KeyHit(Asc("B")) If Cannons < 1 Goto Ending2 EndIf A.Projectile = New Projectile A\dmg = 3 A\img = CopyImage(CannonBall) A\typeP = 2 A\xv# = GetXV#(Angle) A\yv# = GetYV#(Angle) A\x = 200 A\y = 400 .Ending2 EndIf End Function Function ProjectileCollide(PR.Projectile,AT.attacker) If ImagesOverlap(PR\img,PR\X,PR\Y,AT\img,AT\X,AT\Y) Return True EndIf End Function Function ShowLevelScreen(levelX) DrawImage NextLevelMenu,0,0 Text "Level " + Level,450,350 End Function Function GetXV#(ang#) Return Cos#(ang#) End Function Function GETYV#(ang#) Return Sin#(ang#) End Function |
| ||
I provided a solution to your timer post. |