Jump to content


Newbie_37

Member Since 01 Aug 2009
Offline Last Active Apr 30 2012 03:28 AM

Topics I've Started

Enemy shooting to direction they facing

16 December 2011 - 05:22 AM

I already created patrolling enemies, static enemies and some random enemies. Now, my problem is with patrolling enemies. Patrolling enemies are dumb and they shoot bullets according to specified time, so basically, they shoot bullets without the presence of the player, some others, when player is in range, attack to the player.

My problem is, patrolling enemies change their sprites depending on the direction, but how to do this with bullets? They shoot bullets but always in the same direction and I want them to shoot bullets where they facing (4 possible ways: up, down, left or right). If you have played Battle City on Nintendo NES or the Famicom you will understand how those tanks behaved.

Any input is greatly appreaciated.

What I did with enemy2 (patrolling red tank)

Create event
Set path (I have a path for them)
Creave moving instance of enemy_bullet (speed 4 - relative)
Set alarm 0 to 200

Alarm 0 event
Creave moving instance of enemy_bullet (speed 4 - relative)
Set alarm 0 to 200 //in order to create a loop

Step
Execute a piece of code
switch(direction)
{
case 180: sprite_index = enemy_2left;break;
case     0: sprite_index = enemy_2right;break; 
case   90: sprite_index = enemy_2up;break; 
case 270: sprite_index = enemy_2;break;}

Basic AI code

12 December 2011 - 06:31 AM

Posted Image

Allright guys, second question of the day. The code I am using for my enemy object (a tank) is the following:

In the create event
dirTimer = room_speed
speed = 0.4 //speed of the tank

Step event
dirTimer -= 1
if dirTimer <= 0
{
dirTimer  = room_speed
direction = choose(0,90,180,270);
switch(direction)
{
case 180: sprite_index = enemy_1left;break;// sprite for left
case     0: sprite_index = enemy1_right;break; //  sprite for right
case   90: sprite_index = enemy1_up;break;  // sprite for up
case 270: sprite_index = enemy_1;break;}} // sprite for down


Now this simply code takes the speed of the room in order to change the direction (randomly). Now my problem is, all my enemies (if I place more of 1 object of the same tank) change direction at the same time (of course) and they actually are quite...stupid.

In the collisions with bricks or other map objects I put
-reverse horizontal
-reverse vertical

I guess if I put these two in the same collision event, the program will choose one or only choose the first one?

I know I could make another AI using paths, but it becomes redundant and the pattern keep repeating again and again.

So is there any other code or any suggestion in order to make my enemy movement better? I didn't add enemies shooting at the moment, because I am trying to figure out the movement first.

Control flow of bullets

11 December 2011 - 11:54 PM

Posted Image

This is the game I am working on (Battle City Adventure).
Now, I already worked on the range of the bullet (it will increase with certain item)
Also, if you press 1 time spacebar only 1 bullet is shot, if you left pressed spacebar only 1 bullet is shot.
Now, my problem is, if you hit spacebar like a maniac (like in most shooters) you get a very cool flow of bullets that looks like actually cheating, I would love to control the flow and no matter if you keep pressing like a crazy man, if there's 1 bullet already fired you need to wait to that bullet to 1. To die in range 2. To hit target or wall .
I've tried several things but nothing seems to work in the way I want to.

Thanks in advance.

-Ben

Problem with bricks and variable

11 November 2011 - 12:21 AM

So, in this game you have to clear all the bricks in order to access to the next level.
I thought I could do this just using a variable bricks and when it goes to zero, then go to the next level.

But I don't know where to put it. I put it on the CREATE brick (that disappear when collides with ball), with Var Bricks 1.
When ball collision with brick, turn this variable to 0 (but only for this brick, not all of them).

Well anyway, I made a mess.

There's anything more easy to implement in order to achieve this?

Bullet range

06 November 2011 - 08:59 PM

So I create my character, my gun-system (thanks to the forum) and finally I could make the bullet go to the way character is facing (using facing variable).
Now, my problem is, I don't think the bullet should go all the way to the other side of the screen (it destroys itself when collides with a solid object, like a wall), but still, some of the corridors/halls in my game are quite large and the bullet travels all the way to the other side and I really don't want that.

It's there a way to give the bullet a small range? I was thinking that maybe I should create an animation (my char is 16 x 16 pixels) of the bullet going like 48 or more pixels long in order to cut it, but it's a lot of work that maybe can be solved through code.

Thanks in advance.