Skip to content

Instantly share code, notes, and snippets.

@wndxlori
Last active May 8, 2019 21:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wndxlori/fdee58d65070719299a54f6877b61d02 to your computer and use it in GitHub Desktop.
Save wndxlori/fdee58d65070719299a54f6877b61d02 to your computer and use it in GitHub Desktop.
DragonRuby Game Toolkit Tutorial - Galaga clone...a new beginning
# the first 2 or 4 values of the primitive conventionally are x, y, (w, h, or x2, y2)
# the last 4 values conventionally are r, g, b, a (color)
# custom values for primitive are in the middle
# labels x, y, text, size, alignment, r, g, b, a
# sprites x, y, w, h, path, angle, alpha
# lines x, y, x1, y1, r, g, b, a
# solids x, y, w, h, r, g, b, a
# borders x, y, w, h, r, g, b, a
# sounds ".wav|.ogg"
def defaults game_state
game_state.game.ship_x ||= game_state.grid.w_half - 33
end
def render game_state
game_state.outputs.labels << [ game_state.grid.w_half, game_state.grid.h - 10, "Galaga", 1, 1, 0, 0, 255, 255]
game_state.outputs.sprites << [ game_state.game.ship_x, 10, 66, 66, "ship_blue.png", 90]
if game_state.game.bullet_x
game_state.outputs.sprites << [ game_state.game.bullet_x, game_state.game.bullet_y, 10, 10, "blue_bullet.png"]
end
end
def calc game_state
if game_state.game.bullet_x
game_state.game.bullet_y += 8
if game_state.game.bullet_y > game_state.grid.h
game_state.game.bullet_x = game_state.game.bullet_y = nil
end
end
game_state.game.ship_x -= game_state.grid.w if game_state.game.ship_x >= game_state.grid.w
game_state.game.ship_x += game_state.grid.w if game_state.game.ship_x <= 0
end
def inputs game_state
if game_state.inputs.controller_one.key_held.right
game_state.game.ship_x += 10
elsif game_state.inputs.controller_one.key_held.left
game_state.game.ship_x -= 10
end
if ( game_state.inputs.controller_one.key_down.a ||
game_state.inputs.controller_one.key_down.b ) && !game_state.game.bullet_x
game_state.game.bullet_x = game_state.game.ship_x + 28
game_state.game.bullet_y = 76
end
end
def tick game_state
defaults game_state
render game_state
calc game_state
inputs game_state
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment