Skip to content

Commit

Permalink
more physics objects, organized readme
Browse files Browse the repository at this point in the history
-added three new small physics objects
-made physics objects clickable
-draggable objects now have selection indicator
-made projectiles red again
-fixed shooting
-fixed information overlay not displaying correct object info
-updated and organized readme
  • Loading branch information
confuzedskull committed Oct 4, 2014
1 parent e8cf46d commit 876925a
Show file tree
Hide file tree
Showing 15 changed files with 208 additions and 149 deletions.
4 changes: 2 additions & 2 deletions include/cursor.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ static color box_color;//RGB values
static bool highlighting;
static std::vector<bool> highlighted_objects;
static int selected_object;
static object * left_clicked_object;
static object * right_clicked_object;
static clickable_object * left_clicked_object;
static clickable_object * right_clicked_object;
static bool set_rally;
static bool left_clicked_an_object;
static bool right_clicked_an_object;
Expand Down
1 change: 0 additions & 1 deletion include/draggable_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class draggable_object: public clickable_object, public tangible_object
public:
bool grabbed();//checks if this object was grabbed by the cursor
void mouse_function();//performs a variety of actions dependent on cursor interaction
void render();
void update();
draggable_object();
};
Expand Down
10 changes: 5 additions & 5 deletions include/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@
#include "projectile.h"
#include <vector>

//stores important settings and global variables for the program
//This class stores important settings and global variables for the program
class game
{
public:
static float time;
static float time;//stores the current game time in seconds
static clock_t time_started;
static double time_elapsed;
//below I used pointers because the objects will be created in init_objects()
static std::vector<draggable_object*> draggable_objects;
static std::vector<physics_object*> physics_objects;
static std::vector<rts_object*> rts_objects;
static std::vector<projectile> projectiles;
static int current_projectile;
static void init_objects();
static std::vector<projectile> projectiles;//projectiles don't need to be initialized so they aren't pointers
static void init_objects();//initialize the objects
static void collision_detection();
};
#endif // GAME_H
2 changes: 2 additions & 0 deletions include/movable_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class movable_object: virtual public complex_object
bool rally_set;//whether or not the object has a point to move to
float degrees_rotated;//keeps track of the progress of a rotation animation
float speed;
void set_resting();
bool moving_forward;
bool moving_backward;
bool moving_left;
Expand Down Expand Up @@ -64,6 +65,7 @@ class movable_object: virtual public complex_object
bool move_to_point(float destination_x, float destination_y);
void add_action(int action_no, int times);//adds an action to be performed n times to the action cue
bool perform_actions();//makes the object perform the cued actions
void update();
movable_object();
};
#endif // MOVABLE_H
4 changes: 2 additions & 2 deletions include/physics_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@

#ifndef PHYSICS_H
#define PHYSICS_H
#include "clickable_object.h"
#include "tangible_object.h"
#include "vector2f.h"

//A physics object has physical properties and inherits the ability to detect collision from the tangible object class
class physics_object: public tangible_object
class physics_object: public clickable_object, public tangible_object
{
public:
float mass;
Expand All @@ -35,7 +36,6 @@ class physics_object: public tangible_object
vector2f momentum;
float angular_momentum;
vector2f force;
void set_resting();
void calc_delta_time();
void calc_velocity();
void calc_acceleration();
Expand Down
7 changes: 3 additions & 4 deletions include/projectile.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,18 @@

#ifndef PROJECTILE_H
#define PROJECTILE_H
#include "physics_object.h"
#include "tangible_object.h"
#include "point2f.h"

//A projectile collides with other physics objects
class projectile: public physics_object
class projectile: public tangible_object
{
public:
float range;//how far the projectile can go until it resets
float traveled;//how far the projectile has gone
int power;//how much damage the projectile will make
float speed;
bool fired;
void fire(complex_object source);//an object fires a projectile
void fire(movable_object source);//an object fires a projectile
void update();//updates the projectile's values
void reset();
projectile();
Expand Down
81 changes: 45 additions & 36 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,52 @@
=======
by James Nakano AKA confuzedskull

Troubleshooting:
<Windows>
If the program doesn't run, then you must right click it and select "Run as Administrator"

<Mac>
If the message ""2dworld" was blocked from opening because it is not from an identified developer" do this:
1. Go to System Preferences and click on Security & Privacy
2. Somewhere near the bottom you'll see a message and then a button "Open Anyway". Click it.
3. A prompt will come up saying ""2dworld is a Unix applicaiton downloaded from the internet. Are you sure you want to open it?" Click open.

<Linux>
If you're using Linux, you can probably figure out how to get it running on your own.

Controls:
<Mouse>
-left click object to select
-left drag box around objects to select multiples
-left click empty space to deselect
I. Troubleshooting
A. Windows
1. If the program doesn't run, then you must right click it and select "Run as Administrator"

B. Mac
1. If the message ""2dworld" was blocked from opening because it is not from an identified developer" do the following:
a. Go to System Preferences and click on Security & Privacy.
b. Somewhere near the bottom you'll see a message and then a button "Open Anyway". Click it.
c. A prompt will come up saying ""2dworld is a Unix applicaiton downloaded from the internet. Are you sure you want to open it?" Click open.

C. Linux
1. If you're using Linux, you can probably figure out how to get it running on your own.

II. Controls
A. Mouse
1. Global
a. left click an object to select it
b. left click empty space to deselect
2. RTS Objects
a. left drag down and right to create a selection box
b. right click empty space to set the rally point and make the selected object move to it
c. right click an object to make the selected object follow it
d. right drag to have the selected object follow the cursor
3. Draggable Objects
-left click and drag an object to move it around
-right click empty space to set rally point and make selected object move to it
-right click an object to make selected object follow it
-right drag to have selected object follow cursor
<Keyboard>
-W,A,S,D to move up,left,down,right
-Q and E to rotate
-spacebar to shoot
-i for information overlay
-esc to quit

Known Bugs:
-sometimes objects stop shooting for no reason
-information overlay sometimes crashes
-an object's resting point gets set even when it's moving
-some of the object's physics values do not zero out when object is at rest
-information overlay displays information of wrong object
-having the information overlay up after clicking an object sometimes makes the program crash

B. Keyboard
1. Global
a. i for information overlay
b. esc to quit
2. Physics Objects
a. W,A,S,D to move up,left,down,right
b. Q and E to rotate
c. spacebar to shoot


III. Known Bugs:
A. Global
1. The information overlay sometimes crashes.
B. Physics Objects
1. Sometimes objects stop shooting for no reason.
2. An object's resting point gets set even when it's moving.
3. Some of the object's physics values do not zero out when object is at rest.
C. RTS Objects
1. An object's resting point doesn't get set at all.

Disclaimer:
This program was made using the OpenGL Utility Toolkit(GLUT) created by Mark Kilgard.
I do not own the rights to this API nor do I claim them as my own.
I do not own the rights to this API nor do I claim it as my own.
6 changes: 2 additions & 4 deletions src/cursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ float cursor::xmax = 0.0;
float cursor::xmin = 0.0;
float cursor::ymax = 0.0;
float cursor::ymin = 0.0;
object* cursor::left_clicked_object = new object;
clickable_object* cursor::left_clicked_object = new clickable_object();
int cursor::selected_object = 0;
bool cursor::left_clicked_an_object = false;
std::vector<bool> cursor::highlighted_objects(game::rts_objects.size(),false);
bool cursor::right_dragging = false;
object* cursor::right_clicked_object = new object;
clickable_object* cursor::right_clicked_object = new clickable_object();
bool cursor::right_clicked_an_object = false;
bool cursor::left_dragging = false;
bool cursor::grabbed_an_object=false;
Expand Down Expand Up @@ -80,12 +80,10 @@ void cursor::selection_box()//this is the box that is created when user clicks a
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(box_color.r,box_color.g,box_color.b,0.5);
glBegin(GL_QUADS);

glVertex2f(xmin, ymin); // The bottom left corner
glVertex2f(xmin, ymax); // The top left corner
glVertex2f(xmax, ymax); // The top right corner
glVertex2f(xmax, ymin); // The bottom right corner

glEnd();
}
}
22 changes: 1 addition & 21 deletions src/draggable_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

bool draggable_object::grabbed()
{
if(cursor::left_dragging &&
if(cursor::left_dragging && !cursor::highlighting &&
isless(cursor::left_drag.x,xmax) &&
isgreater(cursor::left_drag.x,xmin) &&
isless(cursor::left_drag.y,ymax) &&
Expand Down Expand Up @@ -79,26 +79,6 @@ void draggable_object::mouse_function()
}
}

//draggable objects need their own render method because they do not have a selection indicator
void draggable_object::render()
{
glColor3f(primary_color.r,primary_color.g,primary_color.b);//color the square with object.primary_color
if(!rendered)
{
std::clog<<"object#"<<number<<": "<<name<<'('<<type<<')'<<" rendered."<<std::endl;
rendered=true;
}
if(visible)
{
glBegin(GL_POLYGON);//draws a solid shape
glVertex2f(back_left.x, back_left.y); // The bottom left corner
glVertex2f(front_left.x, front_left.y); // The top left corner
glVertex2f(front_right.x, front_right.y); // The top right corner
glVertex2f(back_right.x, back_right.y); // The bottom right corner
glEnd();//finish drawing
}
}

void draggable_object::update()
{
set_boundaries();
Expand Down
Loading

0 comments on commit 876925a

Please sign in to comment.