Mintoris Forum

Author Topic: Space Invaders II  (Read 18712 times)

rasdini

  • Sr. Member
  • ****
  • Posts: 111
Space Invaders II
« on: Apr 11, 2016, 02:02 AM »
Hey Chuck,
This is what I have so far. I just used some code from Pong III for the framework. I don't understand why the font tile set is visible on the screen. What am I doing wrong here.

sraffens

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 220
Re: Space Invaders II
« Reply #1 on: Apr 11, 2016, 02:28 AM »
I develop with the the setting that varables are not auto initialized. That way you will get an error for any varable that you use but do not initialize.

To fix the numbers in the display, change the atlas from 1024,1024 and increase the atlas size to 2048,1024

the "universe16a.png" is a 1024x1024 bit map, so loading it will use an atlas of 1024x1024

I changed the font map from 0,400 to 1024,0

You must be aware of the bitmap sizes an place them in the atlas in the correct place.

 Const atlas = GenTileAtlas(2048, 1024)

  ' Put the court background into the atlas
  Const courtTileset = GenTileset(assetDir$ + "universe16a.png")
  GenMapToAtlas atlas, courtTileset, 0, 0

  
  ' Create a font and put it into the atlas
  Const font = GenDefaultFont(1,48,10, "0123456789")
  GenMapToAtlas atlas, font, 1024, 0


Scott
« Last Edit: Apr 11, 2016, 02:39 AM by sraffens »

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: Space Invaders II
« Reply #2 on: Apr 11, 2016, 03:33 AM »
Looks like you are doing great. You have figured out how to position tilesets in the atlas. I left the atlas positioning up to the programmer because it's a task best suited to humans.

I'm feeling really lazy today. I'll dig into this program more tomorrow.

I haven't talked about this very much but you can create tilesets right from bitmaps, so you can draw tilesets at runtime.

I also changed all the drawing commands so they will work when the graphics mode isn't on as long as you have a drawing surface set.

Code: [Select]
' create a bitmap with 10 tiles 96x96 each.
bitmap = CreateBitmap(960, 96)

SetDrawingSurface bitmap

' use drawing commands to draw the tiles

SetDrawingSurface Off

tileset = GenTileset(bitmap)

When I sit down to put a game atlas together I get the notebook out and draw a rectangle with the same proportions as the atlas. In this case the atlas is 2048x1024. Once I have the big atlas rectangle drawn, I draw in each tileset, noting the coordinates of each tileset in the atlas. The goal is to fit all your tilesets into your atlas without overlapping and in as small a space as possible.


You also might want to use Orientation 1 (portrait) for this game.

I'm trying to gather all the game engine constants into one include file.

include "Game Engine Constants.inc"

It's in the new global include directory so it will work in any program.
« Last Edit: Apr 11, 2016, 09:11 PM by Chuck »

rasdini

  • Sr. Member
  • ****
  • Posts: 111
Re: Space Invaders II
« Reply #3 on: Apr 11, 2016, 11:24 AM »
Hey Chuck,
When I execute the program, there is a white line on the left and top of the screen. When I change the position to: -1,-1 from 0,0 to try and eliminate this,  the image disappears and there is a black screen. How can we get rid of the lines?

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: Space Invaders II
« Reply #4 on: Apr 11, 2016, 04:20 PM »
That white line is on the image file (universe16a.png). Edit the graphics file and crop out the white line.

rasdini

  • Sr. Member
  • ****
  • Posts: 111
Re: Space Invaders II
« Reply #5 on: Apr 11, 2016, 05:08 PM »
Gotcha.

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: Space Invaders II
« Reply #6 on: Apr 11, 2016, 08:21 PM »
When you switch to portrait you also have to switch the width and height on the GameEngine On command.

Also you might want to resize that background image to 400x800 or any 1:2 ratio maybe 512x1024. If you don't have photoshop, Gimp is a handy (free) image editing tool. I use it all the time.

www.gimp.org

Post your most recent version so I can work on it for a while. I'll flesh out some of the functionality. After that you can do more fine tuning. I have years of experience with this game engine and it's going to take me a while to pass on all my tricks.
« Last Edit: Apr 11, 2016, 08:55 PM by Chuck »

rasdini

  • Sr. Member
  • ****
  • Posts: 111
Re: Space Invaders II
« Reply #7 on: Apr 12, 2016, 12:43 AM »
Getting ready to create my animated sprites for the enemies. What size do you recommend I make the sprite tiles?
I was planning on landscape mode so there is room on either side for firing, score,  lives and still room for the aliens to move back and forth.

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: Space Invaders II
« Reply #8 on: Apr 12, 2016, 03:04 AM »
Oh ok. Sounds like you have everything under control. I would probably use 96x96 for the game pieces and a second tileset 128x128 for explosions. If that will all fit into the atlas. Then the explosion sprite can be made to grow and fade for extra effect.
« Last Edit: Apr 12, 2016, 03:16 AM by Chuck »

rasdini

  • Sr. Member
  • ****
  • Posts: 111
Re: Space Invaders II
« Reply #9 on: Apr 12, 2016, 06:19 AM »
I already started the art work with 640×64 for a 64×64×10 tileset. Will that work?

Actually, I was thinking of using sprites as particles. Since you have all the tools there, direction, gravity if desired, they can be faded out over time. I mean, it's got everything I would program myself in basic,  which is cumbersome and slower. What do you think? All it would take is a little particle image.

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: Space Invaders II
« Reply #10 on: Apr 12, 2016, 06:32 AM »
Sure all that will work. There is something called particle emitters which would work great, but I left them out of this upgrade. Using sprites for particles will work just fine.

rasdini

  • Sr. Member
  • ****
  • Posts: 111
Re: Space Invaders II
« Reply #11 on: Apr 13, 2016, 01:00 AM »
Yeah, my Dark Basic Professional has particle emitters, but they never behaved the way I wanted. I always made my own like I do in my Mintoris games. I definitely want to check out sprites as particles. I think they will work great. I could create 50 or 100 at a time. Pick random directions, random life spans, random speeds, alpha to change colors, you have fading in there. You can kill sprites. Is there a command to kill after fading out? If not, then I would just add a few milliseconds past the particle life to kill them.

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: Space Invaders II
« Reply #12 on: Apr 13, 2016, 01:56 AM »
I would put all your particles on their own layer, maybe one higher than your main layer. Each layer is limited to 500 sprites.

The onModifier event sub gets triggered when special effects like fade complete. Add the following event sub if it's not already in there. You can set all your emitter sprites to the same sub. Start a fade on the sprite and when the fade completes the following sub is called. I called the sub onSpriteModifier() but you can choose whatever name you like. Different sprites can point to different modifier subs for different effects. Just make sure the parameters (sprite, type) remain the same. Try one event sub and you will be hooked on them. Since it only gets called once when the fade completes, the amount of Basic code needed is usually really small so the event sub executes really fast.

Code: [Select]
SetOnGenSpriteModifierSub sprite, onSpriteModifier()

Sub onSpriteModifier(sprite, type)

  if type = Mod_Fade_Complete then

    GenKillSprite sprite

  endif

End Sub

rasdini

  • Sr. Member
  • ****
  • Posts: 111
Re: Space Invaders II
« Reply #13 on: Apr 13, 2016, 03:30 AM »
Hey Chuck,
Here are the images so far on my first tileset.
There are 2 frames for each sprite. Frame 1 and 2 are alien 1, 3 and 4 are alien2, 5 and 6 are alien 3, 6 and 7 is the boss that flies access the screen. I managed to load it into a tileset. I made it visible in the screen area for you to see. Can you show me now, just to get started, how to position 1 and how to animate it. Then let's see where I can go from there.

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: Space Invaders II
« Reply #14 on: Apr 13, 2016, 08:30 PM »
I've put one alien on the screen, animated it with tiles 1 & 2

I had to make the backgrounds transparent on your alien tileset.

I also scaled your background image to 1024x512. This is close to how the image was being scaled at runtime, but doing it beforehand saves half a meg of atlas space. I also cropped out that white line.

I reduced the atlas size to 1024x1024 and moved your tileset and the font down. Your tileset can grow to 1024x128 which would give you 16x2 or 32 sprites before you have to change the current atlas arrangement.

I just added one alien sprite that bounces off the walls. I think you wanted me to do as little as possible just to get you started.

If you tell me how you want things to move I can set up a onSpriteModifier sub that can make your aliens follow any pattern.
« Last Edit: Apr 14, 2016, 12:55 AM by Chuck »

rasdini

  • Sr. Member
  • ****
  • Posts: 111
Re: Space Invaders II
« Reply #15 on: Apr 14, 2016, 12:36 AM »
Totally awesome:P‼
I'll update this entry as soon as I'm done eating. Then you can reply. Thanks Chuck.
Ok, I'm starting to understand the layers and the naming helps to get it through. Here's where I have problems. There will need to be a group of aliens moving together. I'm sure you remember the game. Now, there can be a direction variable and timing mechanism needed for when you get down to 10 left they go faster, then 5 left and even faster and three left really fast and one goes really really fast. The direction variable could change from positive (to the right) to negative (to the left) whenever any one of the enemies reaches either left or right border. They must also drop a level and if they reach the ground, game over. What I'm getting around to is wouldn't basic be needed for a lot of these action to take place? If so, how do you combine basic with the interrupts or subs?
« Last Edit: Apr 14, 2016, 01:43 AM by rasdini »

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: Space Invaders II
« Reply #16 on: Apr 14, 2016, 02:19 AM »
Ah, yes the group movement problem. I've been thinking about this.

I was going to start to explain it, but maybe I just better write the framework and you can modify it to include all the details.

What I'll do is break all the movements down into stages.

A stage number variable will be stored in each sprite.

I'll use the GenMoveSpriteXY to move the sprites. It generates an interrupt when the movement is complete.

I'll just continue with the code I posted and get back to you soon.

rasdini

  • Sr. Member
  • ****
  • Posts: 111
Re: Space Invaders II
« Reply #17 on: Apr 14, 2016, 03:31 AM »
Ok. Sounds good. Also the animations speed up as they go faster. So that will have to be a variable for this like delaynextanimation, I would probably choose a smaller name like delnxtanim=milliseconds to next animation and use this variable in the animation command for the delay frame factor. Anyway, worked hard today, very tired. Hitting the sack soon. Thanks again Chuck for your patience in helping me with this.

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: Space Invaders II
« Reply #18 on: Apr 14, 2016, 06:40 AM »
Here is my first cut on the movement. The color change was just for debugging. I got hung up for a while. I put the aliens too close together and I hadn't set the collision radius so they were always in collision. If sprites collide it cancels the move operation.

The drift in the formation can be fixed. It's just too late tonight. You just have to wait till the last guy has moved and then tell all the sprites to move to the next stage all at once. That will re-sync all the guys after every move.

Anyway, play around with it for a while and let me know when you need the next piece.
« Last Edit: Apr 14, 2016, 06:53 AM by Chuck »

rasdini

  • Sr. Member
  • ****
  • Posts: 111
Re: Space Invaders II
« Reply #19 on: Apr 15, 2016, 02:02 AM »
Hey Chuck, here's what I got so far. I scaled down the sprites a bit, increased columns to 8. I wanted them to move a little further to the left and right, but couldn't make it happen. I don't know why. Also, when I go to 30 on the spacing, the enemies scramble all over the place. 35 spacing seems to work ok.
Also, I made different enemies in every 2 rows.
Questions:
1. What is "GameEngineConstants.inc"
2. Hash=GenGetSpriteHashTable (sprite)
3. get hash, stage,"Move_Stage"
4. put hash, stage,"Move_Stage"
5. Type=Mod_Move_Complete

could you please explain these commands to me? I mean, I know what includes are but what powers does it give me programming wise? Thanks Chuck