making an enemy

BlitzPlus Forums/BlitzPlus Beginners Area/making an enemy

simo(Posted 2011) [#1]
Hello I'm a new programmer and I'm having trouble with a game I wrote. In my game a bug flys around and you have to shoot it ( I know simple but it's my first game). But right now the bug flys around in this little circle and the player doesn't move. Here is the code for it:



Last edited 2012


Yeshu777(Posted 2011) [#2]
You need to declare x & y as Global.


Global x
Global y



Although it would be better to use the x & y vars that are declared with the player Type.

Best Regards.


simo(Posted 2011) [#3]
Thank you Yeshu777 it really helped. Now I have another problem :the destroying part(as I said before I'm a noob at this so I will have a lot of problems). This is what I entered for it:
If(ImagesCollide(enemyimage,enemy\x,enemy\y,playerimage,x,y))
End
EndIf

If(ImagesCollide(enemyimage,enemy\x,enemy\y,bulletimage,bullet\x,bullet\y))
End
EndIf

When I put that in it gives me an error message saying "Not enough perameters"


Serpent(Posted 2011) [#4]
You have to specify frames as well:
If(ImagesCollide(enemyimage,enemy\x,enemy\y,0,playerimage,x,y,0))
End
EndIf 

If(ImagesCollide(enemyimage,enemy\x,enemy\y,0,bulletimage,bullet\x,bullet\y,0))
End
EndIf



simo(Posted 2011) [#5]
Alright I did that but now it's giving another error message saying "variable must be a type"


simo(Posted 2011) [#6]
Does anybody know what that means?


big10p(Posted 2011) [#7]
Your enemy and/or bullet type variables aren't visible where you have that code (inside a function?). As such, blitz defaults to creating the variables as integers, which is why you're being told they need to be a type when using the \ (as in enemy\x).


simo(Posted 2011) [#8]
Sorry I don't get it.


big10p(Posted 2011) [#9]
Post the code you have so far and I'll try and explain things a bit better.

Last edited 2011


simo(Posted 2011) [#10]
I was able to figure one of the things out but now i can't shoot so this is the code so far:



Last edited 2012


big10p(Posted 2011) [#11]
You were basically getting in a muddle with your global and type field variables. Try this:




simo(Posted 2011) [#12]
Thank you so much its finally working.


simo(Posted 2012) [#13]
Alright I have more questions :P
I have just been updating the same game as before

My first question is: How do I make levels?
I have been trying to figure it out so the game won't compile correctly right now.

My second question is: How do I get animated images in my game?
I have the picture and a frame variable called already.

And my last question a of right now is:Do you have any tips to organize my code?
Right now it is all sloppy and I want it to look better.

Thank you you have been a lot of help on this game,

Simo


simo(Posted 2012) [#14]
Here is the code for the game:



mv333(Posted 2012) [#15]
How do I make levels?

Upload the images and sounds if you can, so we can try the game and see what the level looks like.



How do I get animated images in my game?

Check out the example code from LoadAnimImage



it is all sloppy




Last edited 2012


simo(Posted 2012) [#16]
How do you upload images and sounds?


Matty(Posted 2012) [#17]
You need to have some web space available, or use a free hosting service and upload the images and sounds in a zip file to that web space.

You cannot upload files to the blitzforums themselves, but you can upload them somewhere else and link to them.


simo(Posted 2012) [#18]
How about I just email you, would that be okay? :P

Last edited 2012


simo(Posted 2012) [#19]
How about I just email you, would that be okay? :P
Sorry it says it twice I accidentally resent it :P

Last edited 2012

Last edited 2012


simo(Posted 2012) [#20]
Matty?


Matty(Posted 2012) [#21]
Sorry simo...I wasn't sure how to reply to your post. I don't have a PC at home and use the blitzforums from work. I rarely write programs or develop games anymore (in my spare time that is - I work as a programmer at work and try to avoid it in my spare time now) but I try to help people out on the blitzforum where I can...or discuss things in general discussion.

Sorry I should have responded earlier.

from Matt


NarGarzhvog(Posted 2012) [#22]
How would you do this if you wanted to make the player.player=new player inside of a function?


psychicbottle(Posted 2013) [#23]
function Make_Player

P.Player = New Player

P\X = 0
P\Y = 0



End Function

I realize you posted a while ago but you didnt ever get a respponse and I can honestly say I dont know if what I said will work but If I am correct than that is all you need


misth(Posted 2013) [#24]
psychicbottle, your answer is correct. Although it could be inside code window :D

Type Player
  Field x,y
End Type

Function MakePlayer.Player() ; .Player indicates that the function returns a type-object called Player
  P.Player = New Player

  P\x = 0
  P\y = 0

  Return P
  ; If you want to continue using this player inside this function, you don't have to return it.
End Function