Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Revision 6:5bea67cc96f9, committed 2020-03-23
- Comitter:
- josh_ohara
- Date:
- Mon Mar 23 15:20:59 2020 +0000
- Parent:
- 5:e5bb95fb308b
- Child:
- 7:06a2558155f0
- Commit message:
- Beginning engine contruction
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Alien/Alien.cpp Mon Mar 23 15:20:59 2020 +0000
@@ -0,0 +1,23 @@
+#include "Alien.h"
+
+
+void Alien::init(int y, int size) {
+ X = WIDTH/2 - Size/2,
+ Y = y,
+ Size = size,
+ Speed = 0.2,
+}
+
+void Alien::draw(N5110 &lcd) {
+ lcd.drawRect(X, Y, Size, Size, FILL_BLACK);
+}
+
+Vector2D Alien::get_position() {
+ Vector2D p = {X,Y};
+ return p;
+}
+
+void Alien::update() {
+ X+=Speed;
+}
+
--- a/Alien/Alien.h Sun Mar 22 19:06:39 2020 +0000
+++ b/Alien/Alien.h Mon Mar 23 15:20:59 2020 +0000
@@ -8,13 +8,14 @@
{
public:
- void init(int x, int y, int speed);
+ void init(int y, int size);
void draw(N5110 &lcd);
void get_position();
- void update(Direction d,float mag);
+ void update();
public:
- int x;
- int y;
- int speed;
+ int X;
+ int Y;
+ int Speed;
+ int Size;
};
\ No newline at end of file
--- a/BulletS/BulletS.cpp Sun Mar 22 19:06:39 2020 +0000
+++ b/BulletS/BulletS.cpp Mon Mar 23 15:20:59 2020 +0000
@@ -4,11 +4,11 @@
{
}
-void Bullet::init(int size, int speed, int Height) {
+void Bullet::init(int size, int x, int y) {
Size = size;
- Speed = speed;
- X = WIDTH/2 - Size/2; //Middle of the ship
- Y = HEIGHT - Height; //Top of the ship Height is ship Height
+ Speed = 0;
+ X = x; //x=Middle of the ship
+ Y = HEIGHT; //y=Top of the ship Height is ship Height
}
void Bullet::draw(N5110 &lcd)
@@ -18,7 +18,7 @@
void Bullet::update() {
if(pad.A_pressed()) {
- Speed = 1; //shoots bullet if pad a pressed
+ Speed = 1; //shoots bullet if pad a pressed
Y -= Speed;
}
}
--- a/BulletS/BulletS.h Sun Mar 22 19:06:39 2020 +0000
+++ b/BulletS/BulletS.h Mon Mar 23 15:20:59 2020 +0000
@@ -7,7 +7,7 @@
{
public:
Bullet();
- void init(int size, int speed);
+ void init(int size, int x);
void draw(N5110 &lcd);
void update();
Vector2D get_position();
@@ -18,7 +18,6 @@
int X;
int Speed;
int Size;
- int Height;
// bool Hit;
};
--- a/Rock/Rock.h Sun Mar 22 19:06:39 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,13 +0,0 @@
-
-#include "mbed.h"
-#include "N5110.h"
-#include "Gamepad.h"
-
-class Rock
-{
-
-public:
- void init(int x, int y, int size);
- void draw(N5110 &lcd);
- Vector2D get_position();
- int get_size();
--- a/Ship/Ship.cpp Sun Mar 22 19:06:39 2020 +0000
+++ b/Ship/Ship.cpp Mon Mar 23 15:20:59 2020 +0000
@@ -1,11 +1,11 @@
#include "Ship.h"
-void Ship::init(int y, int height, int width)
+void Ship::init(int height, int width)
{
X = WIDTH/2 + width/2;
Y = HEIGHT - height;
- height = Height;
- width = Width;
+ Height = height;
+ Width = width;
Speed = 0.5;
}
--- a/Ship/Ship.h Sun Mar 22 19:06:39 2020 +0000
+++ b/Ship/Ship.h Mon Mar 23 15:20:59 2020 +0000
@@ -7,10 +7,10 @@
{
public:
- void init(int y, int height, int width); //dimensions of the ship without shooter, y position is bottom of the screen
- void draw(N5110 &lcd); //Draws basic rectangle ship
- Vector2D get_position(); //Returns position of ship
- void update(Direction d, float mag); //Interface between joystick and ship control
+ void init(int y, int height, int width); //dimensions of the ship without shooter, y position is bottom of the screen
+ void draw(N5110 &lcd); //Draws basic rectangle ship
+ Vector2D get_position(); //Returns position of ship
+ void update(Direction d, float mag); //Interface between joystick and ship control
int get_height();
int get_width();
// void set_life(int l);
@@ -19,7 +19,7 @@
int Height;
int Width;
int X;
- int Y; //y value of ship
- int Speed; //speed of ship
+ int Y; //y value of ship
+ int Speed; //speed of ship
// bool Life;
};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/SpaceInvaderEngine/SpaceInvaderEngine.h Mon Mar 23 15:20:59 2020 +0000
@@ -0,0 +1,49 @@
+#ifndef SPACEINVADERENGINE_H
+#define SPACEINVADERENGINE_H
+
+#include "mbed.h"
+#include "N5110.h"
+#include "Gamepad.h"
+#include "BulletS.h"
+#include "Ship.h"
+#include "Alien.h"
+
+#define BORDER 2
+
+class SpaceInvaderEngine
+{
+
+public:
+ SpaceInvaderEngine();
+ void init(int ship_height, int ship_width, int ship_bullet_size, int speed, int alien_size);
+ void read_input(Gamepad &pad);
+ void update(Gamepad &pad);
+ void draw(N5110 &lcd);
+
+private:
+
+ void read_input(Gamepad &pad);
+ void draw(N5110 &lcd);
+ void check_alien_collision(Gamepad &pad)
+
+ Alien A1;
+ Ship S1;
+ BulletS BS1;
+
+ int S1_height;
+ int S1_width;
+ int A1_size;
+ int B1_size;
+
+ int A2y;
+
+ int S1y;
+
+ int B1x;
+
+ Direction D;
+ float Mag;
+
+};
+
+#endif
\ No newline at end of file