From 317e3dbd05f621ec5acf35d36881b4b132a7c946 Mon Sep 17 00:00:00 2001 From: kyDoleuc04 <46973452+kyDoleuc04@users.noreply.github.com> Date: Mon, 25 Mar 2019 14:21:53 -0400 Subject: [PATCH 1/6] Updated from Brython Server: 3/25/2019 2:21:52 PM --- spaceshooter.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/spaceshooter.py b/spaceshooter.py index 651f607..8076772 100644 --- a/spaceshooter.py +++ b/spaceshooter.py @@ -7,3 +7,16 @@ Write and submit a program that implements the spacewar game: https://github.com/HHS-IntroProgramming/Spacewar """ +from ggame import App, Sprite, ImageAsset, Frame, CircleAsset +from ggame import SoundAsset, Sound, TextAsset, Color +import math +from time import time + +class Stars(Sprite): + + asset = ImageAsset("images/starfield.jpg") + width = 512 + height = 512 + + def __init__(self, position): + super().__init__(Stars.asset, position) From 501b2c1744b2508e9a988e7bbfdf18942f037865 Mon Sep 17 00:00:00 2001 From: kyDoleuc04 <46973452+kyDoleuc04@users.noreply.github.com> Date: Tue, 11 Jun 2019 20:42:43 -0400 Subject: [PATCH 2/6] Updated from Brython Server: 6/11/2019 8:42:42 PM --- spaceshooter.py | 113 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 111 insertions(+), 2 deletions(-) diff --git a/spaceshooter.py b/spaceshooter.py index 8076772..333d1c1 100644 --- a/spaceshooter.py +++ b/spaceshooter.py @@ -1,7 +1,7 @@ """ spaceshooter.py -Author: -Credit: +Author: kyDoleuc04 +Credit: Andrew, Matt, Tristan, Greg Assignment: Write and submit a program that implements the spacewar game: @@ -12,6 +12,9 @@ import math from time import time +width = 700 +height = 500 + class Stars(Sprite): asset = ImageAsset("images/starfield.jpg") @@ -20,3 +23,109 @@ class Stars(Sprite): def __init__(self, position): super().__init__(Stars.asset, position) + +class Sun(Sprite): + + width = 80 + height = 76 + asset = ImageAsset("images/sun.png", Frame(0, 0, width, height)) + + def __init__(self, position): + super().__init__(Sun.asset, position, CircleAsset(32)) + self.mass = 30*1000 + self.fxcenter = 0.5 + self.fycenter = 0.5 + +class spaceship(Sprite): + asset = ImageAsset("images/four_spaceship_by_albertov_with_thrust.png", Frame(227,0,292-227,125), 4, 'vertical') + + def __init__(self, position): + super().__init__(spaceship.asset, position) + self.vx = 1 + self.vy = 1 + self.vr = 0 + self.v = 0 + self.thrust = 0 + self.thrustframe = 1 + self.initposition = position + SpaceGame.listenKeyEvent("keydown", "space", self.thruston) + SpaceGame.listenKeyEvent("keyup", "space", self.thrustoff) + SpaceGame.listenKeyEvent("keydown", "left arrow", self.turnleft) + SpaceGame.listenKeyEvent("keyup", "left arrow", self.turnoff) + SpaceGame.listenKeyEvent("keydown", "right arrow", self.turnright) + SpaceGame.listenKeyEvent("keyup", "right arrow", self.turnoff) + self.fxcenter = self.fycenter = 0.5 + def step(self): + vx = -sin(self.rotation)*self.v + vy = -cos(self.rotation)*self.v + self.x += vx + self.y += vy + boom = self.collidingWithSprites(Sun) + self.rotation += self.vr + if self.x > myapp.width: + self.x = 0 + if self.x < 0: + self.x = myapp.width + if self.y > myapp.height: + self.y = 0 + if self.y < 0: + self.y = myapp.height + if len(boom) > 0: + explosion((self.x,self.y)) + self.visible=False + self.x = 300 + self.y = 200 + self.v = 0 + self.rotation = 0 + self.thrust = 0 + self.visible = True + if self.thrust == 0 and self.v >= 0.1: + self.v -= 0.1 + if self.thrust == 1 and self.v == 0: + self.v = 1 + if self.thrust == 1: + self.setImage(self.thrustframe) + self.thrustframe += 1 + if self.thrustframe == 4: + self.thrustframe = 1 + if self.v < 12: + self.v *= 1.1 + else: + self.setImage(0) + def thruston(self, event): + self.thrust = 1 + def thrustoff(self, event): + self.thrust = 0 + def turnleft(self, event): + self.vr = 0.1 + def turnoff(self, event): + self.vr = 0 + def turnright(self, event): + self.vr = -0.1 + def controldown(self, event): + if command == "forward": + self.thrust = 40.0 + self.imagex = 1 + self.setImage(self.imagex) + def controlup(self, event): + command = self.keymap[event.key] + if command == "forward": + self.thrust = 0.0 + self.imagex = 0 + self.setImage(self.imagex) + +class SpaceGame(App): + def __init__(self, width, height): + super().__init__() + stars = Stars((0,0)) + stars.scale = self.width/stars.width + self.ss = spaceship((300,200)) + Sun((self.width/2,self.height/2)) + def step(self): + for ship in self.getSpritesbyClass(spaceship): + ship.step() + for exp in self.getSpritesbyClass(explosion): + exp.step() + +myapp = SpaceGame(width, height) +myapp.run() \ No newline at end of file From a36abf19a53c3572230f6147e795d28f24f28140 Mon Sep 17 00:00:00 2001 From: kyDoleuc04 <46973452+kyDoleuc04@users.noreply.github.com> Date: Tue, 11 Jun 2019 20:42:45 -0400 Subject: [PATCH 3/6] Updated from Brython Server: 6/11/2019 8:42:45 PM From ec6ad2c9dd7492ca66bb8c840df4668bd57897bd Mon Sep 17 00:00:00 2001 From: kyDoleuc04 <46973452+kyDoleuc04@users.noreply.github.com> Date: Fri, 14 Jun 2019 10:55:47 -0400 Subject: [PATCH 4/6] Updated from Brython Server: 6/14/2019 10:55:47 AM --- spaceshooter.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/spaceshooter.py b/spaceshooter.py index 333d1c1..f891cfa 100644 --- a/spaceshooter.py +++ b/spaceshooter.py @@ -9,7 +9,7 @@ """ from ggame import App, Sprite, ImageAsset, Frame, CircleAsset from ggame import SoundAsset, Sound, TextAsset, Color -import math +from math import sin, cos from time import time width = 700 @@ -121,11 +121,7 @@ def __init__(self, width, height): stars.scale = self.width/stars.width self.ss = spaceship((300,200)) Sun((self.width/2,self.height/2)) - def step(self): - for ship in self.getSpritesbyClass(spaceship): - ship.step() - for exp in self.getSpritesbyClass(explosion): - exp.step() + myapp = SpaceGame(width, height) myapp.run() \ No newline at end of file From 844f2e9736dd30315f1ede2bd02665e9405cb656 Mon Sep 17 00:00:00 2001 From: kyDoleuc04 <46973452+kyDoleuc04@users.noreply.github.com> Date: Mon, 17 Jun 2019 10:31:41 -0400 Subject: [PATCH 5/6] Updated from Brython Server: 6/17/2019 10:31:43 AM --- spaceshooter.py | 48 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/spaceshooter.py b/spaceshooter.py index f891cfa..f728628 100644 --- a/spaceshooter.py +++ b/spaceshooter.py @@ -45,7 +45,7 @@ def __init__(self, position): self.vy = 1 self.vr = 0 self.v = 0 - self.thrust = 0 + self.thrust = 0.5 self.thrustframe = 1 self.initposition = position SpaceGame.listenKeyEvent("keydown", "space", self.thruston) @@ -70,7 +70,7 @@ def step(self): self.y = 0 if self.y < 0: self.y = myapp.height - if len(boom) > 0: + if boom: explosion((self.x,self.y)) self.visible=False self.x = 300 @@ -114,13 +114,47 @@ def controlup(self, event): self.imagex = 0 self.setImage(self.imagex) +class explosionn(Sprite): + + asset = ImageAsset("images/explosion1.png", Frame(0,0,128,128), 10) + + def __init__(self, position): + super().__init__(explosionn.asset, position) + self.image = 0 + self.center = (0.5, 0.5) + + + def step(self): + self.setImage(self.image//2) + self.image = self.image + 1 + if self.image == 10: + self.destroy() + class SpaceGame(App): + def __init__(self, width, height): - super().__init__() - stars = Stars((0,0)) - stars.scale = self.width/stars.width - self.ss = spaceship((300,200)) - Sun((self.width/2,self.height/2)) + super().__init__(width, height) + asset = ImageAsset("images/starfield.jpg") + Sprite(asset,(0,0)) + Sprite(asset,(512,0)) + Sprite(asset,(0, 512)) + Sprite(asset,(512, 512)) + Sprite(asset,(1024, 512)) + Sprite(asset,(1024, 0)) + spaceship((100,100)) + Sun((300,200)) + def step(self): + for ship in self.getSpritesbyClass(spaceship): + ship.step() + for explosion in self.getSpritesbyClass(explosionn): + explosion.step() + + def register(self, keys): + commands= ["left", "right", "forward"] + self.keymap= dict(zip(keys, commands)) + [self.app.listenKeyEvent("keydown", k, self.controldown) for k in keys] + [self.app.listenKeyEvent("keyup", k, self.controlup) for k in keys] + myapp = SpaceGame(width, height) From c44011962c83b092ab6de878ced13817f53ac69d Mon Sep 17 00:00:00 2001 From: kyDoleuc04 <46973452+kyDoleuc04@users.noreply.github.com> Date: Mon, 17 Jun 2019 10:32:50 -0400 Subject: [PATCH 6/6] Updated from Brython Server: 6/17/2019 10:32:52 AM --- spaceshooter.py | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/spaceshooter.py b/spaceshooter.py index f728628..7c716be 100644 --- a/spaceshooter.py +++ b/spaceshooter.py @@ -35,6 +35,22 @@ def __init__(self, position): self.mass = 30*1000 self.fxcenter = 0.5 self.fycenter = 0.5 + +class explosionn(Sprite): + + asset = ImageAsset("images/explosion1.png", Frame(0,0,128,128), 10) + + def __init__(self, position): + super().__init__(explosionn.asset, position) + self.image = 0 + self.center = (0.5, 0.5) + + + def step(self): + self.setImage(self.image//2) + self.image = self.image + 1 + if self.image == 10: + self.destroy() class spaceship(Sprite): asset = ImageAsset("images/four_spaceship_by_albertov_with_thrust.png", Frame(227,0,292-227,125), 4, 'vertical') @@ -71,7 +87,7 @@ def step(self): if self.y < 0: self.y = myapp.height if boom: - explosion((self.x,self.y)) + explosionn((self.x,self.y)) self.visible=False self.x = 300 self.y = 200 @@ -114,21 +130,7 @@ def controlup(self, event): self.imagex = 0 self.setImage(self.imagex) -class explosionn(Sprite): - - asset = ImageAsset("images/explosion1.png", Frame(0,0,128,128), 10) - - def __init__(self, position): - super().__init__(explosionn.asset, position) - self.image = 0 - self.center = (0.5, 0.5) - - - def step(self): - self.setImage(self.image//2) - self.image = self.image + 1 - if self.image == 10: - self.destroy() + class SpaceGame(App):