Space Invaders Programming (BlitzPlus)

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Guest

Post by Guest »

(didn't see your post about accusing me of stealing my program from the generious person that let me use his sprites)

Okay, that was heartless. I spent freaking HOURS working on that, and now must suffer because I used maneesh's sprites. You don't believe I did it? Open that damn demo and copy the source code please. This is mine.:

Code: Select all

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Marcel Fabry Jaenisch  ;;;;;
;;      9/1/0/4           ;;;;;
;;     5:17 A.M.          ;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; enable the game graphics
Graphics 640,480

;set the back buffer
SetBuffer BackBuffer()
SeedRnd MilliSecs()

Type player
	Field x,y
	Field life
	Field gun
	Field frame
End Type

Type bullet
	Field x,y
	Field gun
	Field direction
End Type
	
Global player.player = New player

player\x = 200
player\y = 400
player\life = 50
player\gun = 1
player\frame = 6

large_bg = LoadImage ("stars.bmp")
Small_bg = LoadImage ("starsfarther.bmp")
player_sheet = LoadAnimImage ("PlayerV2.bmp",68,64,0,13)

Global fasttilemovement = 0
Global slowtilemovement = 0
Global rightframehelper, rightturnoff, leftframehelper,leftturnoff

bg_music = PlayMusic ("interim nation - future experience.mp3")
While Not KeyHit(1)
	Cls
	
	If Not ChannelPlaying(bg_music) 
		bg_music = PlayMusic ("interim nation - future experience.mp3")
	EndIf
	
	fasttilemovement = fasttilemovement + 2
	slowtilemovement = slowtilemovement + 1

	Userinput()

	TileImage large_bg,0,fasttilemovement
	TileImage small_bg,0,slowtilemovement
	
	If 	fasttilemovement = 200 Then fasttilemovement = 0
	If 	slowtilemovement = 200 Then slowtilemovement = 0
	
	DrawImage player_sheet,player\x,player\y,player\frame

	Flip
Wend

Function userinput()
	
	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 KeyDown(203) Then 
		If Not KeyDown(205)
		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 KeyDown(208) Then 
		If Not KeyDown(200)
		player\y = player\y + 4 
		EndIf
	EndIf
;;;;;;;;;;;;;;;;;;;;;;;;;
If KeyDown(200) Then 
		If Not KeyDown(208)
		player\y = player\y - 4 
		EndIf
	EndIf


End Function 	
If anyone here still doesn't believe me, then they can go fuck themselves. I can even send you almost 15 orinignal games with hand made sprites that lead up to this, showing my first time I got jump to work, first tim ei got something to animate, first game with ai, first game a backround, ect. Need I show them?

Hell, I even have my first text based game, where you could actually save your charactor's stats.

NOW DON'T GIVE ME THAT BULLSHIT THAT I COPIED MANEESH!!!
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

Let me explain before you have a heart attack. First off, I never accused you of stealing any code.
The ships look exactly the same and the way the ship rotates left and right when you move is exactly the same.
I stated that the sprites looked exactly the same even the rotating ones. As for thew copyright thing, when I put a mr. green smiley face it usually means I'm kidding. I'm using the mario graphics no matter what. People know it belongs to nintendo, its not like I'm selling it. I'll put their name in the creds though.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

Back to the actuall topic.

Yep, I remember my first space invaders. Its was back in the day when I was always making games for our Ti83 plus'. Ok, I'll admit it, it wasn't that good but what do you expect for a calculator. You could only shoot 1 bullet at a time so that did sort of add stratagy. Hmm.... I wonder if I still have that thing.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

Oh, I'm not sure if you noticed this or not in your code...

Code: Select all

   If Not ChannelPlaying(bg_music) 
      bg_music = PlayMusic ("interim nation - future experience.mp3") 
   EndIf 
I experimented with the ChannelPlaying a while back and found that it slowed down game speed massively. But the only way I know how to keep bg music playing is to know the length of the song, then to start the music back up after that amount to milisecs. Since you probably don't have alot processing at this point you may not notice it. But later on when the game gets bigger, you could try the following to see if it is slowing stuff down.

Code: Select all

;This belongs in the main loop
if keydown(50) = false;key M
	If Not ChannelPlaying(bg_music) 
		bg_music = PlayMusic ("interim nation - future experience.mp3") 
	EndIf
EndIf
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
Guest

Post by Guest »

OMG! I saw that Maneesh fellow's demo. He used the exact same sprites as I did. I'm sorry I was an ass, I didn't know. Now I see why you could think that. Oh, and now I updated my game. It Still isn't a game, but you can now shoot, and enemies, a random number form 1 to 9 appear when you hit ctrl. (I did this to see If I had correctly made them spin.)

But I am still having a problem.....The first ones drawn on the screen spin fine. So do the second pair, usually, but when I hit CTRL again, the new ones don't spin. Can anyone help me out and tell me why not?

Here's my source code. I Didn't label the new parts because they are just there temporary.

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
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 enemy_sheet = LoadAnimImage("enemy1_V1.png",68,38,0,9)

;;;;;;;;;;;;;;;;;;;;;;;
;; 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
; 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
	
	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()
			
	; 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
	
	; 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()

	generate_enemy(1)
	drawenemy()

End Function
		
		
Function drawenemy()
For enemy.enemy = Each enemy

	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
	
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 = 1
			enemy\vy = 1
			enemy\frame = 0
			enemy\toughness = 1
			
		Next
	EndIf
	
	If occured > 3 Then
    	occured = 0
		exospasms = False
	EndIf
	
End Function
Why I named one of my variables exospasms, don't ask me. I must have been drunk. (That drunk part was sarcasm, BTW. I don't intend on getting drunk anytime soon. I'm not a stoner fag who drinks.)
Guest

Post by Guest »

Code: Select all

Code: 

;This belongs in the main loop 
if keydown(50) = false;key M 
   If Not ChannelPlaying(bg_music) 
      bg_music = PlayMusic ("interim nation - future experience.mp3") 
   EndIf 
EndIf
GREAT idea! I never thought of that.
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

I can't really help you because I don't know what the code does... I mean, I can't run the code cause i don't have the images and such.

BUT, as for the Background Music, you can use the technique I made for the Mario game. First you have to open up your music file an see how many seconds long it is (don't confuse with minutes). Then take that number and multiply by 1,000 to turn it into milliseconds. Take a look at the code below.

Code: Select all

;BackGround Music Vars.
Global chnBgMusic         ;pointer to music channel
Global MusicStartTime    ;holds current computer time in milli.
Global MusicLength        ;holds lenght in milli of the song.
Global MusicAddress$    ;holds location of the music file.


;Set the location of the file
MusicAddress$ = "interim nation - future experience.mp3"


;Main Game Loop
While KeyDown(1) = False

	;If the time has passed or song not even playing, play music and reset vars.
	If MilliSecs() - MusicStartTime > MusicLength
		chnBgMusic = PlayMusic(MusicAddress$)
		MusicStartTime = MilliSecs()
		MusicLength = 246 * 1000
	EndIf

Wend
Whats cool about this is that you can change music just by adjusting the address and lenght variable.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Post by MarauderIIC »

So you mean you hit ctrl once, works fine. ctrl twice, works fine. ctrl third time, it doesn't?

Try using print things to output the status of the variables you suspect might be the culprits. (For example, exospasms might not be getting itself set to true for some reason).
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
Don Pwnious
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 833
Joined: Tue Jun 15, 2004 5:32 pm
Location: on the streets wit my j23
Contact:

Post by Don Pwnious »

Arce wrote:a random number form 1 to 9 appear when you hit ctrl. (I did this to see If I had correctly made them spin.)
What spins?

And ill see what i can do..

oh yeh i dont really like that background so you should make your own like this:
I dont really know if it works

Code: Select all

;;;;;;;;;;;;;;;;;;;;;;;;;;
;;using a dotted field;;;; 
;background;;;;;;;;;;;;;;;
;BY: The Phantom 9/11/04;;
;;;;;;;;;;;;;;;;;;;;;;;;;;

; intialize

;Graphics set up
Graphics 640, 480 ; or any choice for your game

; Seed the Rnd Generator
SeedRnd MilliSecs() ; yes the power of random

; the Constants

; the lenth for blocks (notice plural)
Const lenth = 100	 ; choose another if you wish

; the height for blocks
Const height = 100	; again choose another if you want

; how much dots per block
Const dots = 50	; more if you want

; time for the images
fieldimage = CreateImage(lenth,height,0)

; now for the random dots
For loop = 0 To dots
	SetBuffer ImageBuffer(fieldimage)

	;put dots on
	Plot Rnd(lenth), Rnd(height)

Next

;back to normal
SetBuffer BackBuffer()
;end of intializing


; main loop
While (Not KeyDown(1))

TileImage fieldimage

Wend

;end
Last edited by Don Pwnious on Sat Sep 11, 2004 3:28 pm, edited 1 time in total.
1/8th time- 14secs
1/8th speed - 110mph
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

I hate randomly generated backgrounds, they never look good especially when tiled.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
Guest

Post by Guest »

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

	
	
	
	
	
	
	
	
	
Guest

Post by Guest »

Oh, and I too hate randomly tiled backrounds. They don't don't look good.

I made my backround look kinda 3Dish by tiling 4 images that move at differnt speeds. I personally think it looks kinda good.
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

I might be best if you just posted the problem area of your code next time... it would cut down in the search and destroy crap. Hmmm... Well actually, we might need to know varaible declarations.... I don't know.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
User avatar
Don Pwnious
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 833
Joined: Tue Jun 15, 2004 5:32 pm
Location: on the streets wit my j23
Contact:

Post by Don Pwnious »

lol cool 3dish
1/8th time- 14secs
1/8th speed - 110mph
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Post by Falco Girgis »

God dammit arce, nobody is going to search through that huge thing for anything, especially not you. Use your brain, find the area that is screwed up. I swear to god, if you post that huge jarled, blitz disgrace again, I'll shove it up your ass! :?
Post Reply