Created
February 26, 2012 19:26
-
-
Save RobertShippey/1918458 to your computer and use it in GitHub Desktop.
Scape Invaders - Tony
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Space Invaders Project.cpp : Defines the entry point for the application. | |
// Author: | |
// ID: | |
// Version: | |
// Date: 17 Feb 2012 | |
// Description: | |
#include "stdafx.h" | |
#include "gwin.h" | |
const int drawsPerFlight = 100; | |
class position | |
{ | |
public: | |
int x; | |
int y; | |
int dx; | |
int dy; | |
position(); | |
}; | |
class vector | |
{ | |
public: | |
position start; | |
position end; | |
position offset; | |
position drawpos[100]; | |
}; | |
position::position() | |
{ | |
} | |
class playership | |
{ | |
public: | |
vector vec; | |
position pos; | |
playership(); | |
void drawPlayer(GWindow &Gwin); | |
void move(GWindow &Gwin); | |
void moveLeft(); | |
void moveRight(); | |
void moveUp(); | |
void moveDown(); | |
void shoot(GWindow &Gwin); | |
private: | |
int speed; | |
GSprite ship; | |
GImage image1; | |
}; | |
//class bullet | |
//{ | |
//public: | |
// vector vec; | |
// position pos; | |
// bullet(); | |
// | |
// void drawBullet(GWindow &Gwin); | |
//private: | |
// GSprite bullets; | |
// GImage image2; | |
// | |
//}; | |
int main() | |
{ | |
GWindow Gwin; | |
// Clear the Gwin window | |
bool quitting = false; | |
playership Myplayership; | |
/*bullet Mybullet;*/ | |
while(!quitting) | |
{ | |
if(Keyboard.isPressed(GwinKeyNames::CURSOR_RIGHT)) | |
{ | |
Myplayership.moveRight(); | |
} | |
if(Keyboard.isPressed(GwinKeyNames::CURSOR_LEFT)) | |
{ | |
Myplayership.moveLeft(); | |
} | |
if(Keyboard.isPressed(GwinKeyNames::CURSOR_UP)) | |
{ | |
Myplayership.moveUp(); | |
} | |
if(Keyboard.isPressed(GwinKeyNames::CURSOR_DOWN)) | |
{ | |
Myplayership.moveDown(); | |
} | |
Myplayership.move(Gwin); | |
Gwin.clear(BLACK); | |
Myplayership.drawPlayer(Gwin); | |
//if(Keyboard.isPressed(GwinKeyNames::SPACE)) | |
//{ | |
// Mybullet.drawBullet(Gwin); | |
// Myplayership.shoot(Gwin); | |
//} | |
Gsleep(20); | |
Gwin.refresh(); | |
} | |
Gwin.refresh(); | |
Gsleep(1000); | |
// Wait for a key to be pressed | |
Keyboard.waitKey(); | |
return 0; | |
} | |
playership::playership() | |
{ | |
image1.loadImage("playership.png"); | |
image1.resize(40,40);//Appropriate scale of image. | |
ship.attachImage(&image1);//add playership image to sprite image list | |
ship.setAnimationFrameTime(20); | |
pos.x = 280; //strating position of playership | |
pos.y = 400; //playership at bottom of the screen | |
pos.dx = 0; //update position - added to x so increment position. | |
speed = 6; | |
} | |
void playership::drawPlayer(GWindow &Gwin) | |
{ | |
ship.x = pos.x; | |
ship.y = pos.y; | |
ship.update(); //updates animation | |
ship.render(); //draws sprite on screen | |
} | |
void playership::move(GWindow &Gwin) | |
{ | |
if(pos.x<=0) | |
{ | |
pos.x = 0;//stops playership going off the screen(left) | |
} | |
if(pos.x>= Gwin.getWidth()-40) | |
{ | |
pos.x = Gwin.getWidth(); | |
pos.x = pos.x - 40;//stops playership going off the screen(right) | |
} | |
if(pos.y<=0) | |
{ | |
pos.y=0;//stops playership going off the screen(top) | |
} | |
if(pos.y>=Gwin.getHeight()-40) | |
{ | |
pos.y=Gwin.getHeight(); | |
pos.y=pos.y-40;//stops playership going off the screen(bottom) | |
} | |
} | |
void playership::moveRight() | |
{ | |
pos.dx = speed;//dx moves to right, increment by 2. | |
pos.x = pos.x + pos.dx; | |
} | |
void playership::moveLeft() | |
{ | |
pos.dx = -speed; //dx becomes minus 2, moving playership left. | |
pos.x = pos.x + pos.dx; | |
} | |
void playership::moveUp() | |
{ | |
pos.dy = -6; | |
pos.y = pos.y + pos.dy; | |
} | |
void playership::moveDown() | |
{ | |
pos.dy = 6; | |
pos.y = pos.y + pos.dy; | |
} | |
// | |
//bullet::bullet() | |
//{ | |
// image2.loadImage("bullet.png"); | |
// bullets.attachImage(&image2); | |
// bullets.setAnimationFrameTime(20); | |
//} | |
// | |
//void bullet::drawBullet(GWindow &Gwin) | |
//{ | |
// vec.start.x = pos.x + 20; | |
// bullets.x = vec.start.x; | |
// | |
// vec.start.y = pos.y; | |
// bullets.y = vec.start.y; | |
// | |
// vec.end.x = pos.x + 20; | |
// bullets.x = vec.end.x; | |
// | |
// vec.end.y = -10; | |
// bullets.y = vec.end.y; | |
// | |
// bullets.update(); | |
// bullets.render(); | |
//} | |
//void playership::shoot(GWindow &Gwin) | |
//{ | |
// //calculating offset | |
// vec.offset.x = ((vec.start.x - vec.end.x) / 100); | |
// vec.offset.y = ((vec.start.y - vec.end.y) / 100); | |
// | |
// //Calculating whole path | |
// for(int i = 0; i<drawsPerFlight; i++) | |
// { | |
// vec.drawpos[i].x = vec.start.x - vec.offset.x; | |
// vec.drawpos[i].y = vec.start.y - (vec.offset.y * i); | |
// } | |
// | |
// for(int i = 0; i<drawsPerFlight; i++) | |
// { | |
// | |
// | |
// | |
// } | |
//} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment