Giter VIP home page Giter VIP logo

anakataroids's Introduction

Anakataroids

Asteroids in p5.js. They can come from any direction, so.. anakataroids.

Will propbably never be a real game. Just making a thing for my self, to learn. I'll add in stuff at semirandom intervals.

The asteroids will respawn when they go off screen, or when you click the mouse.

How to run it?

I use the 'live p5 panel' inside Visual Studio Code. You can copy the code and paste it in the editor at p5js.org, or you can open index.html in your browser.

Here be dragons

I have a tendency to overcomplicate stuff, so some code might be wonky. if you want to point me in the right direction, ping me or raise an issue :)

What have I learned

the asteroids were not drawn correctly. There was some overlapping paths creating some boolean operations. I thought initially that I did somethignwrong when i called this.sides in the for loop, in essence making a new number of sides for the asteroids, since the asteroid was drawn with extra number of points. After a large amount of console.logs, I realised that i had to reset the vert array after I had drawn the shape. The previous shape was in the array.

The oort() function was the easiest way to spawn asteroids outside the canvas. Instead of doing an if else or sweitch to see if the spawn point was outside the canvas, I decided to use a sin(), cos() to make a rotating point outside the canvas to use a s the spawn point.

I decided to build the oort function with a sine-cos circle since that is the same thing that draws the asteroids.

The asteroids are drawn from 0 degrees to TWO_PI, and the sides are drawn with a for loop iterating over them. Every vsalue of 'i' is mapped from 0 -> PI * 2 so I get radians for a circle. The coords are then modified slightly to create an irregular shape, and stored in the vert-array for drawing in the show()-method.

anakataroids's People

Contributors

chrleon avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.