Skip to content

Game Generator Commands

adamsumm edited this page Sep 8, 2016 · 21 revisions

Overview

This page defines the ASP commands that are produced by the game generator, and how the asp-phaser-generator compiler interprets them.

Default Values

The generator uses abstract names for certain variables. The values of these variables are set in the initial Phaser file, and will be fine-tuned as we continue work.

Numbers

  • low: 1
  • medium/mid: 6
  • high: 11

Locations

  • near: game.width*0.1. (This value is recorded during Phaser brain conversion, and is not in the initial Phaser file).
  • center: (160,220)
  • lower_left: (100,300)
  • upper_right: (300,100)

Sprites

The initial file currently stores image names for "circle", "triangle", "square", "pentagon", and "star". The image names are exactly the same as these except with the file extension ".png".

Colors

The initial file currently stores standard web hex code values for the names "red", "orange", "yellow", "green", "blue", "purple", "pink", "brown", "white", "grey"/"gray", "black", "magenta", and "cyan".

Commands

Resources

Declare a resource variable that is named "r1".

resource(r1)

Set a variable named "r1" to a value of "low", where "low" is another variable.

set(r1, low)

Increase/decrease a variable named "r1" by a value of 10, i.e., r1 += 10 and r1-= 10, respectively.

increase(r1,10)
decrease(r1,10)

Increase/decrease a variable named "r1" by a value of 10 over time, i.e., r1 += 10 * this.game.time.elapsed/10000.0 and r1-= 10 * this.game.time.elapsed/10000.0, respectively. These commands will happen in update().

increase_over_time(r1,10)
decrease_over_time(r1,10)

Entities

Declare an entity variable that is named "e1". Entities are always treated like they are Phaser groups.

entity(e1)

Destroy the entity "e1".

delete(e1)

Set the image for an entity "e1" to be "star". Used inside "initialize()".

set_sprite(e1, star)

Change the color of an entity "e1" to green. Used inside "initialize()".

set_color(e1,green)

Change the angle of an entity "e2" to the value of entity e1's angle. Used inside "initialize()", or as an outcome.

set(angle(e2),angle(e1))

Add a single entity "e1" to the approximate location "top center". Used inside "initialize()".

add(e1,1,location(top,center))

Locations are currently a 3x3 grid on the canvas as follows: rows are "top", "middle", "bottom", while columns are "left", "center", and "right".

Add two entities "e2" to the approximate location of the entity "e1". Used inside "initialize()".

add(e2,2,e1)

Move the entity "e1" towards or away from the cursor. You can also replace "cursor" with the name of any other entity.

move_towards(e1,cursor)
move_away(e1,cursor)

Move the entity "e1" based on compass directions. In this case, "north" is used, but the compiler will understand any cardinal (north, south, east, west) or intercardinal (northeast, northwest, southeast, southwest) directions.

moves(e1,north)

Move the entity "e1" based on rotation. An entity of rotation 0 will move east, west, north, and south for direction commands of forward, backward, left, and right, respectively.

moves(e1,forward)

Apply gravity to the entity "e1".

apply_force(e1,south,mid)

Rotate an entity "e1" in the clockwise ("cw") direction by an amount of 10. You can also rotate an entity in the counterclockwise ("ccw") direction.

rotates(e1,cw,10)

Rotate an entity "e1" such that e1.angle = Math.random() * (360-0) + 0.

rotate_to(e1,random_int(0,360))

Declare that an entity "e1" is draggable.

controlLogic(draggable(e1))

Declare that an entity "e1" is immovable.

static(e1)

Add game.physics.arcade.collide(e1, e2, null, null, this); to the update function.

apply_restitution(e1,e2)

Preconditions and Results (Outcomes)

Preconditions and results use an outcome keyword, which is generally the letter "o" followed by a number. This keyword serves to match preconditions with their results. In this example, if the entities "e1" and "e2" are overlapping, AND if the resource "r1" is less than or equal to zero, then e1 and e2 will be destroyed.

precondition(overlaps(e1,e2,true),o6).
precondition(le(r1,0),o6).
result(o6,delete(e1)).
result(o6,delete(e2)).

The precondition "tick" specifies that the following preconditions and results should be used in the update() function. In this example, the entity "e1" moves forward every update. When "tick" is the precondition, the outcome keyword is also "tick".

precondition(tick,tick).
result(tick,moves(e1,forward)).

Used inside a precondition. Checks if a variable is within a certain threshold. In this example, the check is "if the resource 'r1' is greater than or equal to 0". Besides "ge", one may use "eq", "gt", "lt", or "le" for "loose equality", "greater than", "less than", and "less than or equal to" checks, respectfully.

ge(r1,0)

Used inside a precondition. Checks if an entity "e1" is near another entity "e2".

near(e1, e2)

Used inside a precondition (e.g. "precondition(control_event(click(e1)),o2)"). Checks if the player is currently clicking entity "e1".

control_event(click(e1))

Used inside a precondition, where the check is if game.input.activePointer.isDown.

control_event(button(mouse_button,held))

Used inside a precondition, where the check is game.input.onDown.add(doSomething, this);. doSomething() will be a callback for when the mouse button is pressed.

control_event(button(mouse_button,pressed))

Used inside a precondition. Checks whether entities "e1" and "e2" are overlapping.

overlaps(e1,e2,true)

Used inside a precondition. Indicates that we should call a function with the results after a time delay. The timer "t1" has an associated timerLogic that specifies the delay duration duration and how the listener should be called.

timerElapsed(t1)

Used inside a result. Changes the game mode to "game_loss". One may also change the game mode to "game_win".

mode_change(game_loss)

Declares a game goal to prevent the outcome "o3". In addition to "prevent", one may also request to "achieve" or "maintain" an outcome.

goal(prevent(o3))

Miscellaneous

Indicates that the timer "t1" should have a duration of 3 seconds and only be called once ("single"). In this command, "single" may be replaced with "loop" to call the function repeatedly every three seconds.

timerLogic(t1,3,single)

TODO: Adam, please add more commands here! 👍

#TIER 1# (apply_restitution - singular collides - has been added. Are other types of collide still the top priority?) Requires an overlaps precondition. Instead of Phaser.Physics.Arcade.overlaps being called Phaser.Physics.Arcade.collide is called.

apply_restitution(ENTITY1,ENTITY2))

Entity Faces Something

O.angle = Math.atan2(Other.y- E.y, Other.x - E.x);

result(O,face_towards(E,Other))

KEYBOARD STUFF update() {... if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) { }

precondition(control_event(button(up_arrow, held))

create(){... this.upKey= game.input.keyboard.addKey(Phaser.Keyboard.UP); ... }

update() { ... if (this.upKey.downDuration(1)) { }

precondition(control_event(button(up_arrow, pressed)) ->

Entity.target = Phaser.Point(Math.random() * window.innerWidth, Math.random() * window.innerHeight));

set(target(Entity),random_point)

#TIER 2#

Checking of properties if (E1.state == 1){ }

precondition(eq(state(E1),1),Outcome)

if (E1.state != 1){ }

precondition(neq(state(E1),1),Outcome)

For each entity of type Entity do the following - block: (what we do now)

wrap: update(){... game.world.wrap(Entity, 0, true,horizontal=horizontal,vertical=vertical);

delete: delete the entity if it falls off the given edge of the screen - this would be in update()

edge_condition(Entity,wrap|delete|block,horizontal|vertical).

Produces a Phaser.Point that represents the collision normal between the two entities Phaser.Point.normalize(new Phaser.Point(E1.x-E2.x,E1.y-E2.y))

collision_normal(ENTITY1,ENTITY2)

tempDot = E1.velocity.xVECTOR.x + E1.velocity.yVECTOR.y E1.velocity.x -= 2 * tempDot * normal.x; E1.velocity.y -= 2 * tempDot * normal.y;

reflect_velocity(ENTITY1,VECTOR)

Sample ASP Game

resource(r1).
initialize(set(r1, low)).

entity(e1).

resource(health(e1)).
initialize(set(health(e1), 100)).
initialize(set_sprite(e1, square)).

precondition(le(r1, med), o1).
precondition(gt(health(e1), 0), o1).
result(o1, increase(r1, low)).
result(o1, decrease(health(e1), 1)).