Omnimaga

Calculator Community => Other Calc-Related Projects and Ideas => HP Prime => Topic started by: Handmixer on January 01, 2014, 11:43:14 am

Title: Spaceinvader game
Post by: Handmixer on January 01, 2014, 11:43:14 am
This is my current project
It seems that I am pushing the Prime to its limmits, since it runs slower on the calculator than in the emulator.
This is the raw game, no splach screens or score counting.
I am open for questions and comments

EDIT: After modifying the code and optimizing collision detection it seems to run much faster.
EDIT: Controls is mouse move ship, Enter - fire bullits, Esc - quit
EDIT: Log - change weapon
         Pick up greens for more energy
EDIT: added Alien boss level
EDIT:Some fade in added and levels start outside screen

Title: Re: Spaceinvader game
Post by: DJ Omnimaga on January 02, 2014, 05:23:59 pm
Oh that seems pretty nice so far. Are the graphics placeholders or did you plan to use them? I think a star background would be nice. Also do the graphics use rectangles? If that's the case, that's a quite clever, since DIMGROB sprite data is usually incredibly large compared to if sprites are pre-rendered with RECT_P commands. :)

Btw sorry for not replying sooner, I had a crazy two weeks of work and other activities. >.<

EDIT: Wow this is pretty impressive. I am surprised at the slow on-calc speed, though, considering I had some advanced graphical animations running at over 15 FPS, sometimes much higher (even 3D). I wonder if there isn't some command somewhere that could be slowing the game down considerably or if some for loops could be merged together to reduce the wait (or maybe the amount of bullets on the screen at once reduced to 5-10 max instead of 20)? On the previous firmware, INT() was often the culprit. Or could there be things that could simply be pre-rendered and only updated if necessary? (For example, when you draw the enemy ships, one trick could be to display all of them and all their frames in an extra GROB then instead of drawing each ship individually every loop, you just display the entire GROB in one BLIT command. To update the ship army when one is destroyed or when a  new wave appears, you just do it once an enemy is shot).

Also make sure to remove the WAIT commands for the calc version. :)

One thing I like a lot is how we can use the touch screen to move the ship and ESPECIALLY the explosion at the end, which is very reminiscent from Axe Parser games :).
Title: Re: Spaceinvader game
Post by: XiiDraco on January 02, 2014, 05:51:15 pm
I get entirely how the touchscreen works with its lists but, can't get the syntax for lists right on the prime yet. >_< Then again I pretty much never touch the thing now that I'm working on Abandoned. I should make a game for prime but I'm too lazy.

Anyway nice game Handmixer!
Title: Re: Spaceinvader game
Post by: Handmixer on January 03, 2014, 01:58:37 am
The graphic is predrawn into G3, so that G3 contains all animations. This takes up less space.
In the end of the gameloop there is a WAIT(0.05), this is entirely for the emulator, since it will run to fast.

The gameloop doe contain a lot of FOR-loops for moving, collision detect and rendering, I Think that it may be possible to optimize by reducing to a few FOR loops.

Star background is a good idea. It could be predrawn i G4 and Blit'ed to the render buffer at the beginning of each render cycle
Title: Re: Spaceinvader game
Post by: Hayleia on January 03, 2014, 03:00:53 am
I don't know a lot about the Prime and your game, but if all Invaders move at the same time and in the same direction, couldn't you have one image with them all instead of separate images so that it is faster to move them all ? And when one is hit, you edit the image, would that be possible ?
Title: Re: Spaceinvader game
Post by: DJ Omnimaga on January 03, 2014, 10:48:07 am
The graphic is predrawn into G3, so that G3 contains all animations. This takes up less space.
In the end of the gameloop there is a WAIT(0.05), this is entirely for the emulator, since it will run to fast.

The gameloop doe contain a lot of FOR-loops for moving, collision detect and rendering, I Think that it may be possible to optimize by reducing to a few FOR loops.

Star background is a good idea. It could be predrawn i G4 and Blit'ed to the render buffer at the beginning of each render cycle

I think it wouldn't be a big issue to use more space with a larger GROB to store each possible frame of the entire enemy army rather than each ship, since the calculator has over 16 MB of RAM available for the user. Even with the largest possible army it would most likely take 1 MB or less (assuming, for example, that an enemy army takes a 300x200 area and has 8 frames, each pixel taking 2 bytes). The hardest part would probably be to erase destroyed ships, since you would need to apply a RECT_P command on all 8 frames on the destroyed ship, while also updating your matrix data or whatever.

I the worst case scenario, you could always cut down animation frames to save space.

As for the WAIT command, I think a trick would be to use a TICKS command at the start of the frame then another one at the end. Then you just have to use a WAIT command where you substract both resulting ticks value then divide the result, to keep frame rate consistent.
Title: Re: Spaceinvader game
Post by: Handmixer on January 03, 2014, 12:32:17 pm
Ok, this afternoon I have modified the rendering so that the Whole army is in one GROB.
I was also worried that when 1 alien is killed I had to do 10xRECT and it would affect playing the game, but it hardly does.
I decreased the bombs and bullits to 10, but I think making a queue, rather than a FOR-loop also could reduce som time.
Later I will try to reduce the amount of FOR loops by collecting the movement and the rendering in the same loop.

Thanks for the feedback
Title: Re: Spaceinvader game
Post by: DJ Omnimaga on January 03, 2014, 12:45:54 pm
Yeah, there could possibly be some minor slowdown when killing an alien, more noticeable if everything moves very smoothly. However, I noticed that Zelda: Windwaker for the GameCube, which is a commercially aclaimed game, also does it, so I guess it's not too bad unless the lag is extreme. :P

By the way, how do we use bombs? ???
Title: Re: Spaceinvader game
Post by: Handmixer on January 03, 2014, 02:32:15 pm
The file has been updated.

Bombs are dropped by aliens >B)
Title: Re: Re: Spaceinvader game
Post by: DJ Omnimaga on January 03, 2014, 03:13:28 pm
Ok thanks. I'll try the new version later. :)
Title: Re: Spaceinvader game
Post by: MacBernick on January 03, 2014, 07:54:21 pm
Nice, the aliens are so cute ^^

But why is this so slow ?
I don't get how you're doing collisions detection. Are you sure it's optimal ?
Title: Re: Spaceinvader game
Post by: DJ Omnimaga on January 03, 2014, 08:19:44 pm
I think the slowdown comes from the fact the game allows multiple bullets at once on the screen. I changed the game so only 1 bullet is allowed at once instead of 10 and the game goes much faster. However it becomes incredibly hard lol. I don't get why it runs slow, though, consdiering Trailblazer gets 38 frames per second. It might definitively be worth it to post the code, in case someone here can help optimizing. It could be due to a bug too, such as running the same routine 10 times per loop when it could be ran once. Or maybe the collision method used is that slow?

Title: Re: Spaceinvader game
Post by: Handmixer on January 04, 2014, 04:29:13 am
Collision detection is the problem.
For each frame there is number_of_aliens*possible_number of bullits compares.
I will Work on that to try to improve speed
Title: Re: Spaceinvader game
Post by: Hayleia on January 04, 2014, 04:33:43 am
Can't you just make a loop on the number of bullets, detect if there is a pixel (so an alien), then guess which alien it is with the position of the bullet ?
Title: Re: Spaceinvader game
Post by: Handmixer on January 04, 2014, 05:25:21 am
New version with improved collision detection has been uploaded. Now I just loop the bullits and calculate the position in alien-space. Much better.
Now I will concentrate on the star background and other Things I want in the game.
Title: Re: Spaceinvader game
Post by: Sorunome on January 04, 2014, 06:07:23 am
Nice to see the old classic games invading the prime (you see what i did there? :P )
Anyways, looking nice :)
Title: Re: Spaceinvader game
Post by: DJ Omnimaga on January 04, 2014, 12:13:49 pm
Glad to hear. By the way, by alien-space do you mean the collision is based on the big alien army GROB you now use and once the bullet hits something it tries to detect which one it hits before killing it?


Also for later do you plan to add aliens that requires more than one hit to die?

By the way I moved this with the other HP Prime projects if you don't mind. :)

EDIT: Just tried the new version actually and it got way better. Good job! Only one bug report: When you die then restart, you seem to restart at a random level rather than the first. Also it seems that when you gain energy from the falling circles, the circles and bullets flicker. Is that normal?
Title: Re: Spaceinvader game
Post by: Handmixer on January 04, 2014, 01:53:21 pm
Thanks for the feedback

Yes the random level was a bug, now corrected
I also get the flickering when I pick up a green dot, I need to look into that.

 >B) Space is the aliens locations on the GROB.
Aliens are layed out in 30x30 grid og G4, so it is easy to calculate wich alien a bullet is entering.
I dont use any pixel check, but that would also work.

Boss aliens would be easy to implement; make them harder to kill, and also make them fire more bullits.
Title: Re: Spaceinvader game
Post by: DJ Omnimaga on January 04, 2014, 03:59:42 pm
Aliens are layed out in 30x30 grid og G4

There can be 900 aliens at once on the screen? O.O (unless you meant that each alien is 30x30 pixels?) if you had kept the old alien drawing method (through a loop rather than a giant GROB, you would probably have needed to do like Atari 2600 games and only draw a bunch per frame, which would have resulted in extreme flicker, but kept speed up)

Also nice avatar :D (I also like the title screen btw)

By the way, don't you hate the low framerate in the emulator? Even if stuff runs faster, everything is choppy as hell. when I want to make smooth Youtube videos of HP Prime programs I have to slow them down with extra WAIT commands then speed the resulting video back up. It takes a long while to record.
Title: Re: Spaceinvader game
Post by: timwessman on January 04, 2014, 04:43:09 pm
By the way, don't you hate the low framerate in the emulator?

Well, that was news to me that it was problematic... will put that on the list of things to adjust.
Title: Re: Spaceinvader game
Post by: DJ Omnimaga on January 04, 2014, 04:47:45 pm
It isn't really that much problematic for testing actually, just for showcasing on Youtube and stuff. Sometimes, games might look choppier than it actually is and some people might jump to conclusions saying the Prime isn't all that great because it's slow, when it's not the case. D:

You could maybe make it an option so people can choose, in case it's too demanding for older computers.
Title: Re: Spaceinvader game
Post by: timwessman on January 04, 2014, 07:09:02 pm
How many fps do you want it to update at?
Title: Re: Spaceinvader game
Post by: DJ Omnimaga on January 04, 2014, 07:24:37 pm
The best would probably be the same as the real calc (I think it's around 52 Hz, right?), but 30 would work too I guess.
Title: Re: Spaceinvader game
Post by: Handmixer on January 05, 2014, 05:20:25 am
Aliens are layed out in 30x30 grid og G4

There can be 900 aliens at once on the screen? O.O (unless you meant that each alien is 30x30 pixels?) if you had kept the old alien drawing method (through a loop rather than a giant GROB, you would probably have needed to do like Atari 2600 games and only draw a bunch per frame, which would have resulted in extreme flicker, but kept speed up)

Yes, my  mistake, the aliens takes up 30x30 pixels. But since the actual size of the alien is 26x21 pixels, then a litte math has to be done to check if the bullit is in the void.


Regarding the emualtor discussion.  I understand that in the terms of making a video of what goes on on the emulator screen better accuracy is needed, but when I write code in the connectivity kit, transfer it and then run it. If coding-transfer-run was a smooth flow I wouldnt't care so much about the Emulator since I would use the calculator to run. But today production is not smooth. I use the editor in the connectivity kit, but I have to lookup help in the emulator or in the PDF - context sencitive help should be Integrated in the editor. When I transfer the program the calc goes to Home, and it puts my new program in the bottom of the list, that is counter produtive, at least it should give focus to the program that was uploaded the last. Some basic syntax check could also be done before transfering the program to the calc.
Title: Re: Spaceinvader game
Post by: Handmixer on January 07, 2014, 03:08:06 pm
Another version uploaded. Now includes Alien Boss
Title: Re: Spaceinvader game
Post by: DJ Omnimaga on January 07, 2014, 05:56:32 pm
Wow the boss almost went Touhou on me for a few seconds O.O

I think the boss is way too hard, though, for a level 3 boss. Since we can't move vertically and only have 1 life, he is next to impossible to beat since he almost dodges all your bullets and often traps you between waves of his own bullets, making escape impossible. It might be good to maybe add 3 lives or make the boss so he cannot shoot more than one bunch of bullets in 2 seconds (like in Galaxia and Phoenix).
Title: Re: Spaceinvader game
Post by: Handmixer on January 08, 2014, 12:22:06 pm
Wow the boss almost went Touhou on me for a few seconds O.O

Hehe, I dindn't think he was to hard, but apperently I was wrong.

I will have to Work a Little on the design to allow different level bosses. Also I think the boss should have something extra to show that he is stronger, perhabs bigger or a bar that shows hits.

Also I would like to Work on
 - better level shifts - some text saying "Level 2" or Get ready!"
 - score
 - more than 5 levels
 - Shield or lives - if you have Lifes, what should happen to the level when you die? Reset or rewind

Title: Re: Re: Spaceinvader game
Post by: DJ Omnimaga on January 09, 2014, 09:36:23 am
A bigger sprite would be a good idea. It could also have different eyes to show he is angry or something.

As for level transition you could just make new waves of enemies scroll in like in Galaxian.
Title: Re: Spaceinvader game
Post by: MacBernick on January 11, 2014, 10:33:41 pm
Yeah I love it !

Is it intended that ship warp to new position when touching screen ?
Title: Re: Spaceinvader game
Post by: DJ Omnimaga on February 02, 2014, 12:20:06 am
Btw, I think this is on HP's fault, but if we play Trailblazer for a while then Space Invader, the ship sprites flicker like mad. I think the HP Prime has a memory leak or something requring a reboot for normal behavior to return, but I was wondering if there's a workaround for now?