Mintoris Forum

Author Topic: Space Invaders II  (Read 18713 times)

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: Space Invaders II
« Reply #20 on: Apr 15, 2016, 02:21 AM »
On your Mintoris main console, expand the view so you see the folders. Go into the new Include folder.

Edit Game Engine Constants.inc

You will see that it is just a bunch of Const statements defining commonly used codes.

So, if I say

if type = Mod_Move_Complete then

I am really saying

if type = 8 then

when the game engine calls the onModifierSub(sprite, type) it automatically sets sprite and type. The onModifierSub() gets called for a variety of reasons. Move complete is just one reason it's called. Move complete's type is 8.

As far as the hash tables go, Mintoris Basic supports several types of data structures which can be really useful for arranging data in memory. One type of data structure is a hash table. A hash table is like an array but instead of a numeric index you use a text key. Any type of variable can be put into a hash table. What I did was give each sprite it's own hash table so that you could store any kind of data in a sprite. Put another way, each sprite has it's own local variables.

In the program I store one numeric variable (stage) in each sprite. Each sprite then has it's own stage variable. The stage variable is stored (put) into the hash table under the key "Move_Stage". Later I get stage, add one, then put it back in the hash table. Trust me this will be a very important feature. In an RPG game you might store an inventory array in a hash table. Endless uses.

Download the version below‼
« Last Edit: Apr 15, 2016, 04:03 AM by Chuck »

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: Space Invaders II
« Reply #21 on: Apr 15, 2016, 04:05 AM »
Sorry, I uploaded the wrong version.

This is the version with the movement fixed.

Oh, on that spacing issue, if you put the guys too close together they will collide and break free of the movement sequence. GenSetSpriteCollisionRadius sprite, radius The collision radius (in pixels) will also be used to detect missile collisions.
« Last Edit: Apr 15, 2016, 04:15 AM by Chuck »

rasdini

  • Sr. Member
  • ****
  • Posts: 111
Re: Space Invaders II
« Reply #22 on: Apr 15, 2016, 11:29 PM »
Hey Chuck,
Please download this program. This is where I'm at. Smaller aliens, faster drop, like the original game. Also changed the number of rows and columns to match the original game.
The next challenge will be the barriers. 3 of them for the l player to hide behind. They disintegrate with shots into it so there would have to be a way to do the Graphics for it. I'm going to rack my brain on this one. It will definitely be another layer. Let me know if you havre any ideas.  Thank you Chuck.

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: Space Invaders II
« Reply #23 on: Apr 15, 2016, 11:45 PM »
Wow, that looks great. For the barrier, just use a group of tiles all grouped together, maybe 16x16 tiles and the barrier is 2 tiles high and say 10 wide. Then as the barrier gets hit one of the tiles explodes. Like bricks in a wall.

The barrier should be on the action layer if you want stuff to collide with it. You will need to get into the onSpriteCollisionSub(sprite1, sprite2) soon.

rasdini

  • Sr. Member
  • ****
  • Posts: 111
Re: Space Invaders II
« Reply #24 on: Apr 16, 2016, 02:30 AM »
I type all kinds of stuff Chuck, then bump that stupid red x and it's all gone. Can you please ad a confirm or put it somewhere else. Please.

rasdini

  • Sr. Member
  • ****
  • Posts: 111
Re: Space Invaders II
« Reply #25 on: Apr 16, 2016, 02:45 AM »
Back to what I typed before the red x fiasco. The barriers would have to be higher than 2. The actual game uses pixel perfect collision and it takes several shots to get through it. I'm not looking for that much detail, but I want it to take several shots to get through it. I'm thinking 10x10 or something like that. There's going to be a problem with the collision, as it causes other sprites to move around. I say, create different layers. We don't want collisions with enemies and their own bullets, they will scatter. If say, the enemy layer is the same layer as my bullets. The enemies bullets would be the same layer as my ship and barriers. Then we would have to create 2 player bullets on each layer for each shot that travel together, one on the enemies layers and one on the barriers layer. They could be different colors and shapes. Maybe a blue teardrop shape bullet with a red circle in the middle of the teardrop shape. That way we can detect either collision, barrier or enemy, disintegrate the barrier or kill the enemy, delete both bullet sprites that represented that one bullet. What do you think?

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: Space Invaders II
« Reply #26 on: Apr 16, 2016, 03:10 AM »
I just went to look for the commands and I found that I haven't added them yet. There are switches that allow collisions to be reported to the collision sub, but does not do damage or auto-collide. So, after I add a couple commands you will get a collision interrupt with no other action. Then you can decide what is to happen in your program.

You should start giving each sprite a type

GenSetSpriteType sprite, type

You make up what numbers you use. Define constants. In the collision routine we will use the type to determine what is colliding with what.

-I'll move the buttons on the browser.
« Last Edit: Apr 16, 2016, 09:14 PM by Chuck »

rasdini

  • Sr. Member
  • ****
  • Posts: 111
Re: Space Invaders II
« Reply #27 on: Apr 16, 2016, 03:21 AM »
That would be great. When you say I should give each sprite a type, do you mean in the hash table?

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: Space Invaders II
« Reply #28 on: Apr 16, 2016, 04:01 AM »
The sprite type is a simple integer that is stored in the sprite just for the programmers use.

GenSetSpriteType sprite, type

I would say use just 4 types, player, enemy, player missile, enemy missile (unless you think of other types).

Then in the collision sub we can check the type of the two sprites that are colliding and act accordingly.

type = GenGetSpriteType(sprite)

rasdini

  • Sr. Member
  • ****
  • Posts: 111
Re: Space Invaders II
« Reply #29 on: Apr 16, 2016, 06:31 AM »
That's a nice feature. Solves a lot of problems. Ok, I will get to work on the ship image so we can add it's movement and the barriers as well. I'm beginning to think colors might be cool over black and white, even though my goal was to stay true to the original game. Only thing is I would want every one in a row to be one color. Ok, I'll talk to you later.

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: Space Invaders II
« Reply #30 on: Apr 16, 2016, 09:09 PM »
Heh, I woke up this morning with the intention of adding the missing commands and I found them already in place. I must have been somehow impaired last night ;)

Ok, for all the sprites set

GenSetSpriteRebound sprite, Off

then for each sprite

SetOnGenSpriteCollisionSub sprite, onCollision()

Sub onCollision(sprite1, sprite2)

' Collision logic goes here

End Sub


To make the logic simpler you might have 4 different collision subs, one for players, one for enemy collision and one each for the missles.

When you get the graphics ready post your latest version and ill put the movement logic in. Tell me exactly how you want the movement and fire control to work. Do we need to draw buttons? Sprites can act as buttons too.
« Last Edit: Apr 16, 2016, 09:41 PM by Chuck »

rasdini

  • Sr. Member
  • ****
  • Posts: 111
Re: Space Invaders II
« Reply #31 on: Apr 17, 2016, 01:06 AM »
wow Chuck. Awesome, no big red x anymore. Thank you so much. I couldn't figure out how to draw on your transparent image, so I updated my old one. You'll have to redo the transparency. Sorry. All I added was the base ship. The second to last image is the enemy the passes across the top.
I am going to create a second tileset for the barriers and bullets. I will try to post it tonight.

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: Space Invaders II
« Reply #32 on: Apr 17, 2016, 01:14 AM »
For the barriers. you said that the old game was pixel perfect when you hit a barrier. Well I was thinking since the pixels in the old game were about 1/8" square you could easily replicate each pixel with a sprite.

rasdini

  • Sr. Member
  • ****
  • Posts: 111
Re: Space Invaders II
« Reply #33 on: Apr 17, 2016, 01:37 AM »
Ok Chuck, Here is the second tileset. It contains the animated player bullets. then a tile for the barrier bricks and a simple enemy bullet that can be set to any color.

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: Space Invaders II
« Reply #34 on: Apr 17, 2016, 02:08 AM »
The brick isn't going to work. To get them to line up next to each other the brick has to fill the sprite.

rasdini

  • Sr. Member
  • ****
  • Posts: 111
Re: Space Invaders II
« Reply #35 on: Apr 17, 2016, 02:23 AM »
Ok, you can change it how you need to our create a new tileset if necessary,  but I think the color should stay the same, deep blue. As far as movement, I was thinking of touching the bottom to move your ship to where you touch. Just have the ship up from the bottom a little bit. I was picturing fire buttons on both sides so people can play right or left handed. I was also toying with using tilt to move, or having a menu with the option to touch to move out tilt to move.

rasdini

  • Sr. Member
  • ****
  • Posts: 111
Re: Space Invaders II
« Reply #36 on: Apr 17, 2016, 02:55 AM »
That's weird, the big red x is back.

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: Space Invaders II
« Reply #37 on: Apr 17, 2016, 03:38 AM »
I haven't had time to look at the red x yet. I've been writing reference pages all day.

rasdini

  • Sr. Member
  • ****
  • Posts: 111
Re: Space Invaders II
« Reply #38 on: Apr 17, 2016, 04:00 AM »
I understand, and the manual has total priority over everything. I can't wait for the manual to come out. Here's what I have so far. Whenever you have a chance to look at it. Take your time. Thanks.

Chuck, I just uploaded my latest version which has the speed I want for level 1, then we would decrease that timedelay as the levels increase.
Also, I have the players ship scaled to the final size it should be. Hope the manual is going well.
Hey Chuck, I'm really proud of myself, I managed to add the ship movement all by myself. Well, I used your code, just tweeked it for this purpose. Talk to you later.
« Last Edit: Apr 18, 2016, 03:51 AM by rasdini »

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: Space Invaders II
« Reply #39 on: Apr 18, 2016, 09:58 PM »
I think one tileset is all we need. I'll work on the code more in the next few days.