Skip to content

Instantly share code, notes, and snippets.

@sledge-1
Created March 14, 2017 01:45
Show Gist options
  • Save sledge-1/5a6c42cb2e9fac296f98cc850e6cbee9 to your computer and use it in GitHub Desktop.
Save sledge-1/5a6c42cb2e9fac296f98cc850e6cbee9 to your computer and use it in GitHub Desktop.
#include "ofApp.h"
#include "myship.h"
#include "ofMain.h"
#include "stars.h"
/*
*Taylor Mallory
*HW16 Combined trig functions with the "floating" illusion and made a partner image to float with the original image
*
* to do: create star system, music, possible video background, enemies, lazers, and point system
*
*/
//--------------------------------------------------------------
void ofApp::setup(){
all_Dem_Stars = falling_Stars((star_array[0]), ofGetHeight() - ofGetHeight() - 5, 2.0);
ofSetBackgroundColorHex(000000);
goodBattleShip=myShip(ofGetWindowWidth()/2,ofGetWindowHeight()-40,25.0,35.5);
good_Baby_Ship=myShip(ofGetWindowWidth()/1.8,ofGetWindowHeight()-38,10.0,15.5);
//outgoingLazer = goodLazer(ofGetWindowWidth()/1.99,ofGetWindowHeight()-40, 2.0);
GalagaShip.load("Galaga_ship.png");
spaceFont.load("space age.ttf" , 20);
nebula_Background.load("nebula_wallpaper.jpg");
}
//--------------------------------------------------------------
void ofApp::update(){
ship_move_left_right(goodBattleShip);
ship_move_left_right(good_Baby_Ship);
//moveLazerForward(outgoingLazer);
ship_move_up_down(goodBattleShip);
baby_ship_move_up_down(good_Baby_Ship);
}
//--------------------------------------------------------------
void ofApp::draw(){
//createLazer(outgoingLazer);
nebula_Background.draw(0,0,1024,500);
createShip(goodBattleShip, GalagaShip);
createBabyShip(good_Baby_Ship, GalagaShip);
ofSetColor(255,255,255);
spaceFont.drawString("Score:", ofGetWidth()/2,ofGetHeight()-(ofGetHeight()-15));
string fpsRate = "frame rate: "+ofToString(ofGetFrameRate(), 2);
string frameCount = "frame count: "+ofToString(ofGetFrameNum(), 2);
spaceFont.drawString(frameCount, ofGetWidth()-(ofGetWidth()-5),ofGetHeight()-(ofGetHeight()-45));
spaceFont.drawString(fpsRate, ofGetWidth()-(ofGetWidth()-5),ofGetHeight()-(ofGetHeight()-20));
}
//--------------------------------------------------------------
void ofApp::keyPressed(int key){
if (key == OF_KEY_LEFT){
moveShipLeft(goodBattleShip);
moveShipLeft(good_Baby_Ship);
} else if (key == OF_KEY_RIGHT){
moveShipRight(goodBattleShip);
moveShipRight(good_Baby_Ship);
}
else if (key==OF_KEY_CONTROL){
//createLazer(outgoingLazer);
//moveLazerForward(outgoingLazer);
}
}
//--------------------------------------------------------------
void ofApp::keyReleased(int key){
}
//--------------------------------------------------------------
void ofApp::mouseMoved(int x, int y ){
}
//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::mouseEntered(int x, int y){
}
//--------------------------------------------------------------
void ofApp::mouseExited(int x, int y){
}
//--------------------------------------------------------------
void ofApp::windowResized(int w, int h){
}
//--------------------------------------------------------------
void ofApp::gotMessage(ofMessage msg){
}
//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo){
}
#pragma once
#include "ofMain.h"
class ofApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
struct ship *goodBattleShip;
struct ship *good_Baby_Ship;
struct star *all_Dem_Stars;
ofImage GalagaShip;
struct lazer *outgoingLazer;
ofTrueTypeFont spaceFont;
ofImage nebula_Background;
void keyPressed(int key);
void keyReleased(int key);
void mouseMoved(int x, int y );
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void mouseEntered(int x, int y);
void mouseExited(int x, int y);
void windowResized(int w, int h);
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);
};
#include "myship.h"
#include "ofApp.h"
#include "lazer.h"
double *star_array[]={
(double(ofGetWidth())- double(ofGetWidth())),
double(ofGetWidth())/100,
double(ofGetWidth())/90,
double(ofGetWidth())/80,
double(ofGetWidth())/70,
double(ofGetWidth())/60,
double(ofGetWidth())/50,
double(ofGetWidth())/40,
double(ofGetWidth())/30,
double(ofGetWidth())/20,
double(ofGetWidth())/19,
double(ofGetWidth())/18,
double(ofGetWidth())/17,
double(ofGetWidth())/16,
double(ofGetWidth())/15,
double(ofGetWidth())/14,
double(ofGetWidth())/13,
double(ofGetWidth())/12,
double(ofGetWidth())/11,
double(ofGetWidth())/10,
double(ofGetWidth())/9,
double(ofGetWidth())/8,
double(ofGetWidth())/7,
double(ofGetWidth())/6,
double(ofGetWidth())/5,
double(ofGetWidth())/4,
double(ofGetWidth())/3,
double(ofGetWidth())/2,
double(ofGetWidth())/1.99,
double(ofGetWidth())/1.95,
double(ofGetWidth())/1.9,
double(ofGetWidth())/1.89,
double(ofGetWidth())/1.85,
double(ofGetWidth())/1.8,
double(ofGetWidth())/1.79,
double(ofGetWidth())/1.75,
double(ofGetWidth())/1.7,
double(ofGetWidth())/1.69,
double(ofGetWidth())/1.65,
double(ofGetWidth())/1.6,
double(ofGetWidth())/1.59,
double(ofGetWidth())/1.55,
double(ofGetWidth())/1.5,
double(ofGetWidth())/1.49,
double(ofGetWidth())/1.45,
double(ofGetWidth())/1.4,
double(ofGetWidth())/1.39,
double(ofGetWidth())/1.35,
double(ofGetWidth())/1.3,
double(ofGetWidth())/1.29,
double(ofGetWidth())/1.25,
double(ofGetWidth())/1.2,
double(ofGetWidth())/1.19,
double(ofGetWidth())/1.15,
double(ofGetWidth())/1.1,
double(ofGetWidth())/1.01,
double(ofGetWidth())/1.02,
double(ofGetWidth())/1.03,
double(ofGetWidth())/1.04,
double(ofGetWidth())/1.05,
double(ofGetWidth())/1.06,
double(ofGetWidth())/1.07,
double(ofGetWidth())/1.08,
double(ofGetWidth())/1.09,
};
struct star{
double x;
double y;
double r;
double velocity;
};
double random_velocities[] = {.1,.2,.3,.4,.5,.6,.7,.8,.9};
struct star *falling_Stars(double x, double y, double r){
struct star *these_Stars = (struct star*)malloc(sizeof(struct star));
these_Stars->x=x;
these_Stars->y=y;
these_Stars->r=2.0;
these_Stars->velocity=0;
return these_Stars;
}
void star_picker_and_draw(struct star *star){
for (int i = 0; i <= 62; i++){
star->x = star_array[i];
star_array[i] * (rand() % 3);
if (star_array[i]/2 == star_array[i]){
ofDrawCircle(star->x, star->y, star->r);
star->velocity += random_velocities[i];
}
}
}
#pragma once
#include "ofMain.h"
#include "ofApp.h"
void star_picker_and_draw(struct star *star);
struct star *falling_Stars(double x, double y, double r);
double *star_array[63];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment