blitz basic

For discussions about game development that does not fit in any of the other topics.
Post Reply
acer360
Posts: 32
Joined: Sun Nov 29, 2009 12:48 pm

blitz basic

Post by acer360 »

i am currently working on a small game called oneman army and i need help wiht mty code i learned most of this from youtube and other codes but i keep getting this error: "object does not exsist" for this line :

If ImagesCollide(img_bullet,b\x,b\y,0,img_enemy,a\x,a\y,0) Then

this is the entier code:

Code: Select all

 AppTitle"oneman army"
Graphics 800,600,16,2
timer = CreateTimer(30)

x = 320
y = 400
amx = 3
aspeed = 3
chdir = False
ex = 400
ey = 320
ammo = 1000
life = 1
level = 0
kill = 0


SetBuffer BackBuffer()

img_bg = LoadImage("ground.jpg")
snd_shoot = LoadSound("shoot.wav")
snd_kill = LoadSound("kill.wav")

img_bullet = LoadImage("bullet.png")
Type bullet
	Field x
	Field y
End Type

img_player = LoadImage("player.png")
Type player
	Field x
	Field y
End Type

img_enemy = LoadImage("enemy.png")
Type enemy
	Field x
	Field y
End Type

While Not KeyHit(1)
	TileImage img_bg,1,1

	If KeyHit(57) Then
	DrawImage img_bullet,x,y
		PlaySound(snd_shoot)
		b.bullet = New bullet
		b\x = x
		b\y = y - 5
		ammo = ammo - 1
	EndIf
	For b.bullet = Each bullet
		b\y = b\y - 5
		DrawImage img_bullet,b\x,b\y
		If b\y < 0 Then Delete b
	Next
	If chdir = True Then
		amx = -amx
	EndIf
	chdir = False
	numenemy = 0
	

    For a.enemy = Each enemy
	numenemy = numenemy + 1
	a\x = a\x + amx
	If a\x > 620 Then chdir = True
	If a\x < 20 Then chdir = True
   Next
	
	If ImagesCollide(img_bullet,b\x,b\y,0,img_enemy,a\x,a\y,0) Then
		PlaySound(snd_kill)
		Delete a
		Delete b
		kills = kills + 1
	EndIf  

	If KeyDown(203) Then x = x - 3
	If KeyDown(205) Then x = x + 3
	If KeyDown(200) Then y = y - 3
	If KeyDown(208) Then y = y + 3
	DrawImage img_player,x,y
	DrawImage img_enemy,ex,ey
	
	Text 5,500,"ammo: " + ammo
	Text 5,520,"life: " + life
	Text 5,540,"kills: " + kills
	Text 5,560,"level: " + level

WaitTimer(timer)

Flip
Wend
End
 
the unused variables i will use later on.
XBOX 4 EVER
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: blitz basic

Post by hallsofvallhalla »

first thing check to make sure your images are loading right. Sounds like they are not. You images are in the same directory folder as your main files? BLizt is in fact very basic and will not search for the file, it may need to be /images/bullet.png or wherever the file is located.
acer360
Posts: 32
Joined: Sun Nov 29, 2009 12:48 pm

Re: blitz basic

Post by acer360 »

they load perfectly they are in the same directory as the source code everything worked fine befor i put this in:

For b.bullet = Each bullet
b\y = b\y - 5
DrawImage img_bullet,b\x,b\y
If b\y < 0 Then Delete b
Next
If chdir = True Then
amx = -amx
EndIf
chdir = False
numenemy = 0


For a.enemy = Each enemy
numenemy = numenemy + 1
a\x = a\x + amx
If a\x > 620 Then chdir = True
If a\x < 20 Then chdir = True
Next

For b.bullet = Each bullet
If ImagesCollide(img_bullet,b\x,b\y,0,img_enemy,a\x,a\y,0) Then
PlaySound(snd_kill)
Delete a
Delete b
kills = kills + 1
EndIf
XBOX 4 EVER
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: blitz basic

Post by hallsofvallhalla »

to me it looks like it is checking for the bullet after it has already been deleted or before its created?
acer360
Posts: 32
Joined: Sun Nov 29, 2009 12:48 pm

Re: blitz basic

Post by acer360 »

i don't know i did what was done in other games that i got off tutorials on the internet but this code is mein so maybe you have a fix for it?
XBOX 4 EVER
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: blitz basic

Post by hallsofvallhalla »

i am not positive on this but it looks like you need to change your run time around, like only call the imagecollide if the bullet exists, so create variable called bullet_exists.

Code: Select all

 bullet_exists = 0
then in your bullet creation change the variable

Code: Select all

 If KeyHit(57) Then
bullet_exists = 1
   DrawImage img_bullet,x,y
      PlaySound(snd_shoot)
      b.bullet = New bullet
      b\x = x
      b\y = y - 5
      ammo = ammo - 1
   EndIf
then have it run the collide only if bullet exists

Code: Select all

if bullet_exists = 1 then
If ImagesCollide(img_bullet,b\x,b\y,0,img_enemy,a\x,a\y,0) Then
      PlaySound(snd_kill)
      Delete a
      Delete b
      kills = kills + 1
      bullet_exists = 0;
   EndIf  
   Endif
acer360
Posts: 32
Joined: Sun Nov 29, 2009 12:48 pm

Re: blitz basic

Post by acer360 »

now i getting the error: "'Wend' without 'While'".
XBOX 4 EVER
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: blitz basic

Post by hallsofvallhalla »

arent blitz keywords case sensitive, as in if should be If... be sure that you did not follow that part of my code, i am just typing in psuedo code. make sure if is actually If
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: blitz basic

Post by Jackolantern »

acer360 wrote:now i getting the error: "'Wend' without 'While'".

"wend" ends a "while" block. Just do a text search for "wend", and make sure you don't have one without a while. You may have deleted the "while" when altering your code.
The indelible lord of tl;dr
acer360
Posts: 32
Joined: Sun Nov 29, 2009 12:48 pm

Re: blitz basic

Post by acer360 »

ohhh thanks halls and jack now it works. :D
XBOX 4 EVER
Post Reply

Return to “General Development”