class Data: """place changable state variables here.""" info = coda.TextObject(coda.color.BLACK, 32, "") button = coda.Object(IMAGE_BUTTON) character = coda.Object(IMAGE_CHARACTER_1) background = coda.Object(IMAGE_BACKGROUND) selection = 1
def initialize(window): """Initializes the shooter class.""" MY.player1.location = window / 4 MY.player1.rotation = 90 MY.player1.set_velocity(MY.player1.rotation, 0) MY.player1_hp = PLAYER_MAX_HP MY.player2.location = window - window / 4 MY.player2.rotation = -90 MY.player2.set_velocity(MY.player2.rotation, 0) MY.player2_hp = PLAYER_MAX_HP count = 0 MY.window = window MY.background.location = window / 2 while count < 20: MY.bullets.append(coda.Object(PROJECTILE_ANIMATION[1])) MY.bullet_owner.append(1) count = count + 1 count = 0 while count < 5: if (coda.utilities.rand(0, 1) == 0): image = IMAGE_ASTEROID else: image = IMAGE_ASTEROID_2 obj = coda.Object(image) obj.location = coda.utilities.rand_location(0, MY.window.x) obj.velocity = coda.utilities.rand_location(-50, 50) obj.scale = 2 obj.active = True MY.asteroids.append(obj) count = count + 1
class Data: """Modifiable data""" tilesheet = coda.SpriteSheet("tileset.png", (32, 32)) player_sheet = coda.SpriteSheet("player_sheet.png", (42, 48)) tilemap = [] floors = [] walls = [] player_start_position = coda.Vector2(0, 0) boss_start_position = coda.Vector2(0, 0) player = coda.Object(tilesheet.image_at(0)) boss = coda.Object(BOSS_IMAGE) player_health = 100 boss_health = 300 player_dir = coda.dir.UP timer1 = coda.CountdownTimer(0.1) timer3 = coda.CountdownTimer(0.1) numberOfBullets = 0 bullets = [] bullet_owner = [] rotation_speed = 180 state = 0 last_state = 2 player_text = coda.TextObject(coda.color.BLACK, 24, "Player: ") player_hitbox = coda.Object(PROJECTILE_IMAGE) index = 0 boss_logic = coda.StateMachine() player_logic = coda.StateMachine()
class Data: """place changable state variables here.""" player1 = coda.Object(IMAGE_PLAYER1) player1_hp = 1 player2 = coda.Object(IMAGE_PLAYER2) player2_hp = 1 bullets = [] asteroids = [] bullet_owner = [] maxFrameTime = 0.05 window = coda.Vector2(10, 10) background = coda.Object(IMAGE_BACKGROUND)
def initialize(window): """Initialize Quiz State.""" for index in range(4): MY.buttons.append(coda.Object(IMAGE_BUTTON)) MY.buttons[index].location = (window.x / 2, window.y / 2 + index * 64) obj = coda.TextObject(coda.color.BLACK, 16, "") obj.centered = True obj.location = MY.buttons[index].location MY.button_text.append(obj) MY.question_text.location = (window.x / 2, 64) MY.question_text.centered = True set_up_question()
def load_level(level_name_as_string): """Cleans up resources and loads a specified level. Can be used to reload the same level.""" cleanup() MY.tilemap = coda.utilities.read_file(level_name_as_string + ".txt") obj = MY.player for row in range(len(MY.tilemap)): for column in range(len(MY.tilemap[row])): tile_value = int(MY.tilemap[row][column]) obj = coda.Object(MY.tilesheet.image_at(tile_value)) obj.location = coda.Vector2(column * TILE_SIZE + 16, row * TILE_SIZE + 16) if tile_value == GRASS: MY.floors.append(obj) else: MY.walls.append(obj)
def initialize(window): """Initializes the Introduction class.""" MY.boss_logic.add_state(None, boss_explosion_update) MY.boss_logic.add_state(None, boss_laser_update) MY.boss_logic.add_state(boss_wait_init, boss_wait_update) MY.player_logic.add_state(player_move_init, player_move_update) MY.player_logic.add_state(player_attack_init, player_attack_update) load_level("level1") MY.player.location = (window.x / 2, window.y / 4) MY.boss.location = window / 2 count = 0 while count < 100: MY.bullets.append(coda.Object(PROJECTILE_IMAGE)) MY.bullet_owner.append(BOSS) count += 1
class Data: """place changable state variables here.""" info = coda.TextObject(coda.color.WHITE, 64, "") button = coda.Object(IMAGE_BUTTON) snake = coda.Object(IMAGE_SNAKE_1) selection = 1
class Data: Button = coda.Object(BUTTON_IMAGE)
class Data: """place changable state variables here.""" restart_button = coda.Object(IMAGE_BUTTON) display_text = coda.TextObject(coda.color.WHITE, 24, "Player 2 wins! Play again?")
"""General information on your module and what it does.""" import coda_kids as coda #load sprites constants IMAGE_BUTTON = coda.Image("button.png") IMAGE_SNAKE_1 = coda.Image("Snake_1.png") IMAGE_SNAKE_2 = coda.Image("Snake_2.png") IMAGE_SNAKE_3 = coda.Image("Snake_3.png") IMAGE_SNAKE_4 = coda.Image("Snake_4.png") IMAGE_SNAKE_5 = coda.Image("Snake_5.png") SHEET = coda.SpriteSheet("tileset.png", (32, 32)) ANIMATION = coda.Animator(SHEET, 5) OBJ = coda.Object(ANIMATION) OBJ.scale *= 1 #test stuff SOUND_CHARACTER = [[coda.Sound("Select_1.wav"), coda.Sound("Select_2.wav")], [coda.Sound("Select_1.wav"), coda.Sound("Select_2.wav")], [coda.Sound("Select_1.wav"), coda.Sound("Select_2.wav")], [coda.Sound("Select_1.wav"), coda.Sound("Select_2.wav")], [coda.Sound("Select_1.wav"), coda.Sound("Select_2.wav")]] # text constants TEXT_1 = "I am snake 1!"