You were right, marauder. Thanks. I got that part fixed.
I HATE the background I had, I changed it. I need to post an updated screen shot, so you can see it and what spins.
Today, I got my enemies to move how I wanted them, at least the easiest enemies.
But it makes me so mad, I tried to make it so when my bullet collides with the enemy, the enemy explodes, (8 frames) and plays a sound. Somehow, I failed HORRIBLY. Now, for some unknown reason, it simply doesn't draw the enemies. Can someone help? This is my source code
:
Code: Select all
; enable the game graphics
Graphics 640,480
;set the back buffer
SetBuffer BackBuffer()
SeedRnd MilliSecs()
;;;;;;;;;;;;;;;;;;;;;;;
;; TYPES ;;
;;-------------------;;
;; Player ;;
;; bullet ;;
;; enemy ;;
;;;;;;;;;;;;;;;;;;;;;;;
Type player
Field x,y
Field life
Field draw
Field frame
End Type
Type bullet
Field x,y
Field from
Field frame
Field draw
End Type
Type enemy
Field x,y
Field vx,vy
Field frame
Field toughness
Field active
End Type
Type explosion
Field frame
Field x,y
End Type
;Create a new player
Global player.player = New player
player\x = 200
player\y = 400
player\life = 50
player\frame = 6
player\draw = 1
;;;;;;;;;;;;;;;;;;;;;;
;;Load Images/sounds;;
;;------------------;;
;;Backround ;;
;;player ;;
;;bullets ;;
;;backround music ;;
;;gun sound ;;
;;enemy ;;
;;;;;;;;;;;;;;;;;;;;;;
Global bg_sheet = LoadAnimImage ("stars.png",200,200,0,4)
Global player_sheet = LoadAnimImage ("PlayerV2.png",68,64,0,13)
Global small_bullet = LoadImage ("weak_bullet.png")
Global medium_bullet = LoadImage ("medium_bullet.png")
Global strong_bullet = LoadImage ("strong_bullet.png")
Global bullet_snd = LoadSound ("shot1.wav")
Global enemyexplode_snd = LoadSound ("EXPLODE.wav")
Global enemy_sheet = LoadAnimImage("enemy1_V1.png",68,38,0,9)
Global enemyexplode = LoadAnimImage ("enemyexplosion.bmp",64,64,0,7)
;;;;;;;;;;;;;;;;;;;;;;;
;; Declare Variables ;;
;;-------------------;;
;;;;;;;;;;;;;;;;;;;;;;;
Global mediumtilemovement = 0 ; the movement of the second farthest bg. image
Global fasttilemovement = 0 ; the movement of the closest bg. image
Global slowtilemovement = 0 ; the movement of the farthest bg. image
Global semifasttilemovement = 0 ; the movemnt of the second fastest bg. image
Global rightframehelper, rightturnoff, leftframehelper,leftturnoff ; numbers used to help the player image shift frames
Global backroundtimer = 0 ; a timer that adds 1 every time program goes through main loop,
; helps with tiling slowest bg. image
Global exospasms = True
Global occured = 0
Global drew
Global enemytimer = MilliSecs()
Global timeractive = 1
; play backround music
bg_music = PlayMusic ("interim nation - future experience.mp3")
;;;;;;;;;;;;;;;;;;;;;;;
;; Main Loop ;;
;;-------------------;;
;; keeps pl. on scr ;;
;; tiles all images ;;
;; Moves backround ;;
;; repaets bg. music ;;
;; Draws Player image;;
;;Loops thr functions;;
;;;;;;;;;;;;;;;;;;;;;;;
While Not KeyHit(1)
; clears screen
Cls
If MilliSecs() >= enemytimer+2000 Then
randomize_enemy_direction()
EndIf
backroundtimer = backroundtimer + 1
;loops through music
If Not ChannelPlaying(bg_music)
bg_music = PlayMusic ("interim nation - future experience.mp3")
EndIf
; tiles and moves backrouns
TileImage bg_sheet,0,fasttilemovement,3
TileImage bg_sheet,0,slowtilemovement,0
TileImage bg_sheet,0,mediumtilemovement,1
TileImage bg_sheet,0,semifasttilemovement,2
fasttilemovement = fasttilemovement + 3
semifasttilemovement = semifasttilemovement + 2
If backroundtimer = 2 Then
slowtilemovement = slowtilemovement + 1
backroundtimer = 0
EndIf
mediumtilemovement = mediumtilemovement + 1
; goes through all functions
Userinput()
Bullets()
Enemy()
collisions()
; keeps player on screen
If player\x > 575 Then player\x = 575
If player\x < 0 Then player\x = 0
If player\y > 425 Then player\y = 425
If player\y < 0 Then player\y = 0
; keeps tiles from mooving too far
If fasttilemovement = 200 Then fasttilemovement = 0
If slowtilemovement = 200 Then slowtilemovement = 0
If mediumtilemovement = 200 Then slowtilemovement = 0
If timeractive = 0 Then
enemytimer = MilliSecs()
timeractive = 1
EndIf
; draws player
DrawImage player_sheet,player\x,player\y,player\frame
; flips buffer
Flip
Wend
;;;;;;;;;;;;;;;;;;;;;;
;; Userinput() ;;
;;------------------;;
;;205 (rightkey) ;;
;;203 (leftkey) ;;
;;208 (downkey) ;;
;;200 (upkey) ;;
;;57 (spacebar) ;;
;;;;;;;;;;;;;;;;;;;;;;
Function userinput()
; If you hold down right, move your charactor right, and add one to a variable,
; when the variable is high enough, change the charactor frame,
; when the charactor frame is to the last frame, keep it there,
; when you let go of the button, subtract from the frame number until it's back where it started
If KeyDown(205) Then
If Not KeyDown (203)
player\x = player\x + 4
rightframehelper = rightframehelper + 1
EndIf
EndIf
If rightframehelper > 4 Then rightframehelper = 0
If rightframehelper > 3 Then
If player\frame < 12 Then
player\frame = player\frame + 1
rightframehelper = 0
End If
End If
If player\frame > 6 Then
If Not KeyDown(205) Then rightturnoff = rightturnoff + 1
EndIf
If rightturnoff = 3 Then
player\frame = player\frame - 1
rightturnoff = 0
EndIf
; If you hold down left, move your charactor left, and add one to a variable,
; when the variable is high enough, change the charactor frame,
; when the charactor frame is to the lowest frame, keep it there,
; when you let go of the button, add to the frame number until it's back to where it started
If KeyDown(203) Then
If Not KeyDown(205) Then
player\x = player\x - 4
leftframehelper = leftframehelper + 1
EndIf
EndIf
If leftframehelper > 4 Then leftframehelper = 0
If leftframehelper > 3 Then
If player\frame > 0 Then
player\frame = player\frame - 1
leftframehelper = 0
End If
End If
If player\frame < 6 Then
If Not KeyDown(203) Then leftturnoff = leftturnoff + 1
EndIf
If leftturnoff = 3 Then
player\frame = player\frame + 1
leftturnoff = 0
EndIf
; if you hold the upkey, move you up
If KeyDown(208) Then
If Not KeyDown(200)
player\y = player\y + 4
EndIf
EndIf
; when you hold the downkey, move you down
If KeyDown(200) Then
If Not KeyDown(208)
player\y = player\y - 4
EndIf
EndIf
; when you hit spacebar, play the gun sound and shoot.
If KeyHit(57) Then
PlaySound bullet_snd
createbullet(1)
EndIf
If KeyHit(157) Then
exospasms = True
EndIf
End Function
;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Bullets() ;;
;;----------------------;;
;DO ALL OF THE FOLLOWING ;
;; FUNCTIONS: ;;
;; drawbullets() ;;
;; updatebullets() ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;
Function bullets()
; do these functions
drawbullet()
updatebullets()
End Function
Function drawbullet()
For bullet.bullet = Each bullet
DrawImage small_bullet,bullet\x,bullet\y
Next
End Function
Function createbullet(from)
Bullet.bullet = New bullet
If from = 1 Then
Bullet\x = player\x + 15
Bullet\y = player\y + 5
bullet\from = 1
bullet\frame = 0
bullet\draw = 1
EndIf
End Function
Function updatebullets()
For bullet.bullet = Each bullet
bullet\y = bullet\y - 6
Next
End Function
Function enemy()
For enemy.enemy = Each enemy
For explosion.explosion = Each explosion
generate_enemy(1)
drawenemy()
keep_enemy_on_screen()
If enemy\active = 0 Then
Delete enemy
EndIf
If backroundtimer = 1 Then explosion\frame = explosion\frame + 1
If explosion\frame > 7 Then Delete explosion
DrawImage enemyexplosion,explosion\x,explosion\y,explosion\frame
Next
Next
End Function
Function drawenemy()
For enemy.enemy = Each enemy
If enemy\active = 1
drew = drew + 1
DrawImage enemy_sheet,enemy\x,enemy\y,enemy\frame
If drew > 3
enemy\frame = enemy\frame + 1
EndIf
If enemy\frame = 9 Then enemy\frame = 0
If drew > 4 Then drew = 1
enemy\x = enemy\x + enemy\vx
enemy\y = enemy\y + enemy\vy
EndIf
Next
End Function
Function generate_enemy(toughness)
If exospasms = True Then
enemies = Rnd(1,3)
occured = occured + 1
For i = 1 To enemies
enemy.enemy = New enemy
enemy\x = Rnd(1,575)
enemy\y = Rnd (1,425)
enemy\vx = Rnd (-2,2)
enemy\vy = Rnd (-2,2)
enemy\frame = 0
enemy\toughness = 1
enemy\active = 1
Next
EndIf
If occured > 3 Then
occured = 0
exospasms = False
EndIf
End Function
Function keep_enemy_on_screen()
For enemy.enemy = Each enemy
If enemy\vx = 0 Then enemy\vx = Rnd(-2,2)
If enemy\vy = 0 Then enemy\vy = Rnd(-2,2)
If enemy\vx > 5 Then enemy\vx = enemy\vx - 2
If enemy\vx < -5 Then enemy\vx = enemy\vx + 2
If enemy\vy > 5 Then enemy\vy = enemy\vy - 2
If enemy\vy < -5 Then enemy\vy = enemy\vy + 2
If enemy\x > 575 Then
enemy\x = 570
enemy\vy = enemy\vy + Rnd(-2,2)
enemy\vx = enemy\vx + -enemy\vx
EndIf
If enemy\x < 0 Then
enemy\x = 5
enemy\vy = enemy\vy + Rnd(-2,2)
enemy\vx = enemy\vx + -enemy\vx
EndIf
If enemy\y > 425 Then
enemy\y = 420
enemy\vy = enemy\vy + -enemy\vy
enemy\vx = enemy\vx + Rnd(-2,2)
EndIf
If enemy\y < 0 Then
enemy\y = 5
enemy\vy = enemy\vy + -enemy\vy
enemy\vx = enemy\vx + Rnd(-2,2)
EndIf
Next
End Function
Function randomize_enemy_direction()
For enemy.enemy = Each enemy
enemy\vx = enemy\vx+Rnd(-2,2)
enemy\vy = enemy\vy+Rnd(-2,2)
timeractive = 0
Next
End Function
Function collisions()
For enemy.enemy = Each enemy
For bullet.bullet = Each bullet
If ImagesCollide (enemy_sheet,enemy\x,enemy\y,enemy\frame,small_bullet,bullet\x,bullet\y,0) Then
PlaySound enemyexplode_snd
enemy\active = 0
explosion.explosion = New explosion
explosion\frame = 0
explosion\x = enemy\x
explosion\y = enemy\y
Delete bullet
EndIf
Next
Next
End Function