![]() If you want to commission me to create a game to a This is using WebGL ( or some GPU for other Kha targets ) so is not Solutions like Kha, are more flexible and expandable than AIR so better Occasions ( ie: VideoScribe uses some Haxe and AS3). I could implement this code in Haxe Flash AIR easy enough, it is veryĮasy to mix as3 and Haxe flash code and have done on quite a few Has not been updated recently with latest Kha so if you try in KodeĮditor you may need to tweak the keyboard code checking against latest API. Latest github Kha, but my last knowledge was that Kodegarden test space Template, I think Keyboard interaction details may vary slightly in the Just a quick port - render and update default to static in the You an idea, not sure if it was ideal to use static everywhere - it was I have implemented the same code in the Kha toolkit, it's just to give Relation to both the Kha and Canvas Haxe solutions. Jeff's suplementary reply is very good, please read carefully in The 5 minute coding example has no scaling of the grid,ĭoesn't keep score, and a few other things, but does show impressive coding Under 5 minutes in JavaScript can be seen on youtube at: O device resolution might vary from 86 dpiĪn example of a subset of this game, written in real time in N you are given a window size in pixels, and the Pad the cells by the leftover amount so that the cell grid fills the space Must first figure out how many the proper cell size such that at least 10 cellsĬan fit in the X and Y directions, but no larger than 42 pts in size, thenĭivide the width and height by the number of cells in each direction, and then If the given window size is too small to accommodateĪt least 10 cells in both directions, the cellsize is reduced. Slightly stretched to not have any dead space leftover. The window size will not usually be an even multiple of 42 points, the cells are Window, the game is reset back to the starting state. Starting window size is 700 x 700 interior pixels. Of the screen as a topmost layer at 30% opacity, centered in 28 pt black text, for Snake grows and shrinks, the current size and high score is reported at the top Player can do WEST - SOUTH - EAST to perform a 180 degree turn in 3 consecutive To permit fast maneuvers the direction inputs are queued, so that the A command to move in the direction already in motion So if the snake is traveling east, any attempted Snake, however, to prevent frustration the player is not allowed to move the The arrow keys change the direction of the Then the radii and border thickness are reduced accordingly. If the snake cells had to be reduced from 42 pt due to window size limitations, Remaining cells of the snake are drawn as a rounded rectangle with 2 pt corner radius. The head of the snake is drawn as a rounded rectangle with aĬorner radius of 8 pt and a border of 2 pt dark green. ![]() The snakeĬells are drawn in alternating colors lime green and lawn Squares with 2pts on the right and bottom to create a separation. Snake only is considered to have eaten the apple if the head moves onto theĪpple. TheĪpple may end up on occasion placed inside the body of the snake, however, the The apple is eaten, it is immediately respawned into a random new cell. If the snake moves into the Apple, the snake's length grows by 1. Initially the trail is limited to 5 cells As soon as an arrow key is pressed, the snake begins to move in thatĭirection, and leaves a trail behind. Which is the goal of the snake to eat, is one cell drawn as a circle in HTMLĬolor crimson, and is placed at a random location on the Start, the snake is set to length 1 and positioned at cell (4,4). Since the window size will not be an even number of cells, the cellsĪre stretched slightly so that all screen space is used by the grid. The snake wraps around the board inīoard, drawn solid black, is subdivided into square cells of 42 points at the screen The snake from that cell onward is erased. ![]() If the snake crosses over itself, then a beep is emitted and the part of Is increased by one, a crunch sound is emitted, and the apple is moved to a newĬell. ![]() If the snake moves into the apple the length Runs at 6 frames per second, and the snake moves one cell per frame. Specification by Edward de Jong, version 1 PROGRAMMING CHALLENGE A Snake Game / basic version
0 Comments
Leave a Reply. |