Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Help with creating enemies (sprites)

Author
Message
Turtle Productions
15
Years of Service
User Offline
Joined: 22nd Jan 2009
Location: Finland
Posted: 20th Aug 2011 18:49
Hi! I've been making my 1st game with AppGameKit, but "A wild Problem appeared!" (I encountered a problem): I don't know the best way to create enemies (as sprites).
My code would spawn those automatically, but should I use Type and arrays, or something?
Here's part of my code:


So that is not the whole code, there I spawn a enemy when counter is enough, and put it moving, but there comes an error, that i does not exists (at control enemies).

Any suggestions or help would be greatly appreciated.

Thanks,
TP
XanthorXIII
AGK Gold Backer
13
Years of Service
User Offline
Joined: 13th May 2011
Location:
Posted: 20th Aug 2011 20:00
First I would make sure your Enemy Type has a Sprite ID so you can easily refer to it in your code. I would also make it an array of Enemies so you can update each one in a for/loop.

Those two things will help you out a lot.
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 21st Aug 2011 04:47
Well, I would say that `i` is your problem at a quick read over. You have a variable called `i` that you inc in the prior loop. You then go into a for next loop using i.. it's bound to cause issues, as the loop forces i to step from 20 to imax, yet you set i to be 21 in the prior loop.. It can't be both.

http://s6.bitefight.org/c.php?uid=103081
Daniel TGC
Retired Moderator
17
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 21st Aug 2011 05:32
Hi, I put together a quick program example, showing you how to create 100 enemies, assign them to an array, and keep track of it all. It's simplistic, you tap the screen or click the mouse to create an enemy. There is a maximum enemy count of 100, once you hit that ceiling, the first enemy created is simply recycled and repositioned on the screen. This works on the assumption that in a game siltation, it would have been killed or left the screen by the time 100 shows up. You can also write in a function that checks for destroyed enemies and recycles them instead without too much effort.

Anyway heres the code:

Turtle Productions
15
Years of Service
User Offline
Joined: 22nd Jan 2009
Location: Finland
Posted: 25th Aug 2011 08:57
Thanks! Daniel, that was what I were looking for. But now, I encountered a problem with using "enemies" in my loop. I mean, like controlling them (you can see my code). I bet the problem is with I am trying to use wrong sprite id.

Here's my full code (yeah it is NOT ready yet, so you'll may find something stupid there, I am going to fix 'em)


Error says, that in line 122 I cannot use sprite 0 (it is because of I used DIM, right?) and I don't know what to do..

Any help (again) would be a big thing for me

Thanks,
TP
Turtle Productions
15
Years of Service
User Offline
Joined: 22nd Jan 2009
Location: Finland
Posted: 29th Aug 2011 17:20
Okay, I've found something weird. Why does this problem work when I make enemies be spawned by hitting mouse, but when I make it timed, it will not work.
First code (timed):


And the second code (works)(spawns when GetPointerState()=1)


I wouldn't say that this is a bug, it is that I just don't get it or something. Anyone had this kind of thing with DBPro or AppGameKit or something else? A little help would be a great help for me.

Thanks,
TP
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 29th Aug 2011 18:19
A quick look and I noticed you have record, and record#, are they meant to be the same? That would certainly cause issues.

Turtle Productions
15
Years of Service
User Offline
Joined: 22nd Jan 2009
Location: Finland
Posted: 30th Aug 2011 16:45
DVader, thanks. Now fixed. But I found out what is my problem now.
I am calling my "enemies" in a wrong way for "for - to - next" loop. I tried to fix by many ways but I didn't manage to fix it. There is something wrong in my head, I don't get this somehow...

Enemies can spawn, yeah I figured that out, but I don't know what exaclty should I use in for to next loop to handle my sprites.


Sorry if I sound like stupid or something, I just don't get this thing...

Thanks,
TP
Bursar
16
Years of Service
User Offline
Joined: 17th Sep 2008
Location:
Posted: 30th Aug 2011 17:09
I'd suggest setting your global count variable to 0. The first thing you do in your CreateEnemy function is increment that variable, so your first enemy is actually 'enemy[2]'.

The next thing you need to do is change your CONTROL ENEMIES code as follows:

Note the subtle difference. Instead of having your counting variable increasing from 1 to 100 (which will give you errors if you only have one enemy sprite to start with), you have it go from 1 to 'count'. That way you will only update the enemy elements that are valid.

You also need to move your SetSpritePosition command to underneath the lines that update the enemy position.

Give that a go and let us know how you get on.
Turtle Productions
15
Years of Service
User Offline
Joined: 22nd Jan 2009
Location: Finland
Posted: 30th Aug 2011 18:46
Bursar - you just solved my problem! Very, very big thanks to you, and all who helped me! It is working now!
I understood what I did wrong now. Changed it and PAF - it works. Now that code isn't very cool yet, but my current version is way more better now, this problem was a big barricade for me.
You may hear something of SuperDodge some day at the forums or so


Big thanks!
TP
Bursar
16
Years of Service
User Offline
Joined: 17th Sep 2008
Location:
Posted: 30th Aug 2011 18:53
Excellent news. Now go make a cool game

Login to post a reply

Server time is: 2024-11-21 17:55:04
Your offset time is: 2024-11-21 17:55:04