Jump to content
  • Advertisement
Sign in to follow this  

CHECK CODE PLZ

This topic is 4679 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I wrote this gmae in Blitz BASIC and when i run it there is some error which says "Object does not exist" It happens because of the compiler defined ImageCollide() function I dont know what i did wrong. Heres the code: Graphics 640,480 SetBuffer BackBuffer() AutoMidHandle True Type bullet Field x,y Field image End Type Type enemy Field x,y Field image Field direction End Type Type player Field image Field x,y End Type ;Constants Section Const Leftkey=203,Rightkey=205,Upkey=200,Downkey=208,ESC=1,Spacebar=57 ;Intialize variables to correct values Global player.player=New player player\image=LoadImage("D:\Documents and Settings\Yashesh Pandya\Desktop\ship.bmp") player\x=320 player\y=440 Global bullet.bullet=New bullet bullet\image=LoadImage("D:\Documents and Settings\Yashesh Pandya\Desktop\bullet.bmp") bullet\x=0 bullet\y=0 Global enemy.enemy=New enemy enemy\image=LoadImage("D:\Documents and Settings\Yashesh Pandya\Desktop\enemyship.bmp") enemy\direction=1 enemy\x=0 enemy\y=20 ;Main Loop While Not KeyDown(ESC) Cls TestInput() TestCollisions() UpdateEnemy() PlayerArea() TestCollisions() UpdateBullet() DrawImage enemy\image,enemy\x,enemy\y DrawImage player\image,player\x,player\y Flip Wend ;Function Function TestInput() If KeyDown(Leftkey) player\x=player\x+4 If player\x<=0 player\x=0 EndIf EndIf If KeyDown(Rightkey) player\x=player\x-5 If player\x>=640 player\x=640 EndIf EndIf If KeyHit(Spacebar) bullet.bullet=New bullet bullet\x=player\x bullet\y=player\y EndIf End Function ;Updates enemy Function UpdateEnemy() If enemy\x<0 Or enemy\x>590 enemy\direction=-enemy\direction End If End Function ;Updates the bullets in the game Function UpdateBullet() For bullet.bullet=Each bullet bullet\y=bullet\y-5 If bullet\y<=0 Delete bullet Else DrawImage bullet\image,bullet\x,bullet\y EndIf Next End Function ;player's total play area Function PlayerArea() If player\x<=0 player\x=0 EndIf End Function ;Test for Collisions\Overlaps ;THIS IS WHERE THE PROBLEM OCCURS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*********** Function TestCollisions() If ImagesCollide(bullet\image,bullet\x,bullet\y,0,enemy\image,enemy\x,enemy\y,0) enemy\x=0 enemy\y=20 EndIf End Function

Share this post


Link to post
Share on other sites
Advertisement
[ source ]
[/ source ]
tags would help others read your code much better
or
[ code ]
[/ code ]

without the blanks
unfortunately I don't know anything about basic. It's been some time since QBasic or GWBasic...

Share this post


Link to post
Share on other sites
I'm afraid you might have trouble finding many people that are used to blitz (I sure as heck aren't);
But I gave it a brief skim & here's what I came up with:

you've got a global called bullet of tyep bullet which is allocated upon initialisation

every frame you're checking for collisions between that bullet & the enemy;
and then updating the bullets position UNTIL it hits the vertical edge of the screen (bullet\y<=0)
@ this point you're deleting the bullet
next frame comes along & the collision check function runs again, tries to access the bullet but finds it's been deleted, moans & dies

so you'll want to do some kind of check to make sure there is a current bullet allocated before doing collision checks for it otherwise the "Object does not exist" :P

k? ;]

Share this post


Link to post
Share on other sites
1 question mark is enough..

You are deleting the bullet:
Quote:
If bullet\y<=0
Delete bullet
You are now trying to read it: (but ofcourse it doesn't exist anymore)
Quote:
Function TestCollisions()
If ImagesCollide(bullet\image,bullet\x,bullet\y,0,enemy\image,enemy\x,enemy\y,0)


Now I don't code in blitz so this is based on information I have looked up after you asked the question (I could be wrong),
But the problem seems to be that you're not checking if there is a current bullet before you call the ImagesCollide function

Is the problem occouring straight away or only after the first bullet has gone offscreen?

Is it supposed to look like this?:
Function TestCollisions()
For bullet.bullet=Each bullet
If ImagesCollide(bullet\image,bullet\x,bullet\y,0,enemy\image,enemy\x,enemy\y,0)
enemy\x=0
enemy\y=20
EndIf
Next
End Function

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!