Log In  

Ein-Blaster Alpha
Cart #33112 | 2016-12-06 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA


  1. Animation of Player ship.
  2. Speed-boost when going forward.
  3. Speed-reduced when going Backwards.


  1. Re-configure Star field background.
  2. Shooting.
  3. Enemies.
  4. Scoring.
  5. Lives.
  6. Sounds/Music


Cart #32679 | 2016-11-21 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

Just something I have been working on as I learn to code in PICO-8.

I would appreciate some help in getting the Shooting mechanism up and running and, if at all possible, suggestion on how to make my code shorter.
Also. I know it would be easier to use the sprite editor but I am interested in learning to arrange the pixel through the coding process itself.
As of right now the star field is on a conveyor-belt-style cycle which may change in the future.
The right side bar is the game HUD which will contain Score, Lives, Levels, Power-up (maybe), etc.
The play area will be updated to keep the spaceship within the playing area, and Perhaps a wrap-around on the X axis.

So in essence it's cause and effect, trial and error, as I teach myself LUA.

P#32680 2016-11-21 15:58 ( Edited 2016-12-07 15:34)

You can eliminate a lot of your star code using a loop and the rnd() command...but still recycling like you're doing.

As for moving around, just do all your pixel changing within a single btn() check...

if btn(0) then

Thing for shooting and even with anything there are multiples of (like stars) look at tables (arrays) and loops, they are key. Having a loop in your _draw() and _update() go through each object you have, like a bullet.

for b in all(bullets) do
    if b.y<0 then del(bullets,b) end --delete bullet when off top

...and such from there.

What you've done clearly works, so you're going about things the right way. But in terms of reducing code, always look for where you repeat yourself. That's your first clue that there's a place to reduce code. Group that code like above, or make a function to handle things.

P#32684 2016-11-21 21:06 ( Edited 2016-11-22 02:08)


Thank you so much for the help.

I concur on your comment about the repeating process and this is where I got lost as to how to shorten those codes.
It makes sense now that I've seen it written out.

I am currently contemplating over the Bullet code as I haven't figured out how to get it operational. But I am sure I will figure it out in do time.

The endeavor of programming is quite rewarding. :-)

Thank you, again.

P#32694 2016-11-22 09:46 ( Edited 2016-11-22 14:46)

No problem. When you have multiples of the same type of thing, like a bullet, each copy will have attributes associated with - direction, speed, etc. - and when you create a new copy, add it to a table (array). Then when you cycle through that list with a loop, each copy (object) does whatever it needs to do.

And in the case of Pico-8, you can use a table as a very simple object with properties.

bullet_list={} --empty array that you add bullets to

function create_bullet()

    --define what properties a bullet should have using a table
    local mybullet={

   --add a copy of mybullet to the list; a table within a table

function update_bullets()
   --loops through everything in the list, then you can act on it
   for bullet in all(bullet_list) do
      --use the dot notation to call the table values you defined above

      bullet.y-=bullet.speed --reduces Y of current bullet by speed

      --removes bullet from the list if it goes off the top of the screen
      if bullet.y<=0 then del(bullet_list,bullet) end 

function draw_bullets()
   --looping again, only this time just do drawing things that put the bullet on screen
   for bullet in all(bullet_list) do
      pset(bullet.x,bullet.y,bullet.color) --draws a pixel for each bullet

function _update()

   --pressing X or Z creates a new bullet
   if btnp(4) or btnp(5) then create_bullet() end 

function _draw()

So what this code should do is when you press Z or X, a bullet should appear at a random position and move up off the screen. It should also have a random color.

That code is not the most efficient and obviously not exactly what you want with your spaceship, but should hopefully give you something you can play with and change things to see what happens.

P#32700 2016-11-22 14:13 ( Edited 2016-11-22 19:16)

Thank you, MorningToast, the help is always appreciated.

I haven't gotten to implement or change the coding do to being busy.
The next time I post hopefully I will have updated the game a bit.

P#32717 2016-11-23 13:43 ( Edited 2016-11-23 18:43)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2022-12-04 23:00:05 | 0.010s | Q:17