Skip to content
This repository has been archived by the owner on Mar 30, 2018. It is now read-only.

Commit

Permalink
Planetoids 1.0.
Browse files Browse the repository at this point in the history
Original date: 2008-05-27.
  • Loading branch information
stefansundin committed Dec 24, 2014
1 parent aba817c commit 60e6a56
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 228 deletions.
4 changes: 4 additions & 0 deletions Main.dsp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified Main.ncb
Binary file not shown.
Binary file modified Main.opt
Binary file not shown.
25 changes: 25 additions & 0 deletions Main.plg
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,31 @@
--------------------Configuration: Main - Win32 Release--------------------
</h3>
<h3>Command Lines</h3>
Creating temporary file "C:\DOCUME~1\ky89piho\LOKALA~1\Temp\RSP1E4.tmp" with contents
[
/nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "_AFXDLL" /Fp"Release/Main.pch" /YX /Fo"Release/" /Fd"Release/" /FD /c
"D:\Prog C\MFC\Spel\Planetoids\MainFrame.cpp"
]
Creating command line "cl.exe @C:\DOCUME~1\ky89piho\LOKALA~1\Temp\RSP1E4.tmp"
Creating temporary file "C:\DOCUME~1\ky89piho\LOKALA~1\Temp\RSP1E5.tmp" with contents
[
resources.res /nologo /subsystem:windows /incremental:yes /pdb:"Release/Planetoids.pdb" /machine:I386 /out:"Release/Planetoids.exe"
".\Release\Animation.obj"
".\Release\Main.obj"
".\Release\MainFrame.obj"
".\Release\MyWinApp.obj"
".\Release\Object.obj"
".\Release\ObjectX.obj"
".\Release\Physics.obj"
".\Release\Player.obj"
".\Release\Vector.obj"
"C:\Program\Microsoft Visual Studio\VC98\Lib\WINMM.LIB"
]
Creating command line "link.exe @C:\DOCUME~1\ky89piho\LOKALA~1\Temp\RSP1E5.tmp"
<h3>Output Window</h3>
Compiling...
MainFrame.cpp
Linking...



Expand Down
98 changes: 18 additions & 80 deletions MainFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#include <ctime>
#include <fstream>
#include <sstream>
#include "memdc.h"
#include <windows.h>
#include <mmsystem.h>
#include "fysik/ObjectX.h"

const double pi=3.14159265358979323846;
Expand All @@ -20,7 +21,6 @@ BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_WM_VSCROLL()
ON_WM_HSCROLL()
ON_WM_MOUSEWHEEL()
// ON_WM_SIZE()
ON_COMMAND(IDM_MENU_RESET,OnMenuReset)
ON_COMMAND(IDM_MENU_OPEN,OnMenuOpen)
ON_COMMAND(IDM_MENU_ADD,OnMenuAdd)
Expand Down Expand Up @@ -96,16 +96,23 @@ void CMainFrame::collide(Object* obj1, Object* obj2) {
ss << damage;
animations.push_back(Animation(missile->getPosition(),"Damage",ss.str()));
planet->SetHP(planet->GetHP()-damage);
if (planet->GetHP() <= 0) {
if (planet->GetHP() <= 0 && planet->getName() != "Meteor") {
if (planet->getName() == "Sun") {
animations.push_back(Animation(missile->getPosition(),"Supernova"));
PlaySound("Supernova.wav", NULL, SND_FILENAME | SND_ASYNC);
}
else {
else{
animations.push_back(Animation(missile->getPosition(),"Megasplosion"));
PlaySound("Planet.wav", NULL, SND_FILENAME | SND_ASYNC);
}
}
else {
animations.push_back(Animation(missile->getPosition(),"Explosion"));
stringstream bomb;
bomb << "bomb-0";
bomb << (2+rand()%4);
bomb << ".wav";
PlaySound(bomb.str().c_str(), NULL, SND_FILENAME | SND_ASYNC);
}
}

Expand Down Expand Up @@ -137,32 +144,14 @@ void CMainFrame::collide(Object* obj1, Object* obj2) {
engine->removeObject(planet);
}
engine->removeObject(missile);
/*planet->updateRadius(planet->getRadius()*0.8);
if (planet->getRadius()/scale <= 2) {
engine->removeObject(planet);
}*/
//planet->updateMass(planet->getMass()*0.9);
}
else if (name1 == "Blackhole" || name2 == "Blackhole") {
ObjectX *blackhole=(ObjectX*)(name1=="Blackhole"?obj1:obj2);
ObjectX *planet=(ObjectX*)(blackhole==obj1?obj2:obj1);
//animations.push_back(Animation(planet->getPosition(),"Explosion"));
blackhole->updateRadius(blackhole->getRadius()+0.5*planet->getRadius());
blackhole->updateMass(blackhole->getMass()+0.5*planet->getMass());
engine->removeObject(planet);
}
/*else {
double newRadius=(obj1->getRadius()+obj2->getRadius())/2;
obj1->updateRadius(newRadius);
obj2->updateRadius(newRadius);
}*/
/*else {
Vector vel1=obj1->getVelocity();
Vector vel2=obj2->getVelocity();
obj1->setVelocity(vel2);
obj2->setVelocity(vel1);
}*/

}

void CMainFrame::OnMenuReset() {
Expand Down Expand Up @@ -229,8 +218,9 @@ void CMainFrame::LoadSystem(string fn) {
speed.SetPos(timestep);
float pos,vel,rad,m;
unsigned char r,g,b;
int h;
char name[100];
while (fscanf(f,"%f\t%f\t%f\t%f\t%s\t%d,%d,%d",&pos,&vel,&rad,&m,name,&r,&g,&b) != EOF) {
while (fscanf(f,"%f\t%f\t%f\t%f\t%s\t%d,%d,%d\t%d",&pos,&vel,&rad,&m,name,&r,&g,&b,&h) != EOF) {
for (char *c=name; *c != '\0'; c++) {
if (*c == '_') {
*c=' ';
Expand All @@ -242,11 +232,8 @@ void CMainFrame::LoadSystem(string fn) {
y=pos*sin(angle*pi/180);
velx=vel*cos((90+angle)*pi/180);
vely=vel*sin((90+angle)*pi/180);
ObjectX *newobject=new ObjectX(Vector(x,y), Vector(velx,vely), rad, m, name, r,g,b);
ObjectX *newobject=new ObjectX(Vector(x,y), Vector(velx,vely), rad, m, name, r,g,b,h);
engine->addObject(newobject);
if(name=="Sun"){
newobject->SetHP(10000);
}
}
fclose(f);
file=fn;
Expand All @@ -273,19 +260,13 @@ void CMainFrame::SaveSystem(string fn) {
float position,velocity;
position=sqrt(pow(pos.getX(),2)+pow(pos.getY(),2));
velocity=sqrt(pow(vel.getX(),2)+pow(vel.getY(),2));
fprintf(file,"%f\t%f\t%f\t%f\t%s\t%d,%d,%d\n",position,velocity,p->getRadius(),p->getMass(),name,p->getColorR(),p->getColorG(),p->getColorB());
fprintf(file,"%f\t%f\t%f\t%f\t%s\t%d,%d,%d\t%d\n",position,velocity,p->getRadius(),p->getMass(),name,p->getColorR(),p->getColorG(),p->getColorB(),p->GetHP());
}
fclose(file);
}
}

void CMainFrame::OnPaint() {
//Flicker free DC
/* CPaintDC loldc(this);
CRect rect;
GetClientRect(rect);
CMemDC dc(&loldc,&rect);
*/
CPaintDC dc(this);

dc.SetTextAlign(TA_CENTER);
Expand Down Expand Up @@ -435,7 +416,7 @@ void CMainFrame::OnPaint() {
CBrush brush;
CRect planetrect(middle_x+planet_x-radius,middle_y+planet_y-radius,
middle_x+planet_x+radius,middle_y+planet_y+radius);
if (!start && name != "Blackhole" && name != "Sun" && p1.GetPlanet() != planet && p2.GetPlanet() != planet && planetrect.PtInRect(MousePos)) {
if (!start && name != "Blackhole" && name != "Sun" && name != "Meteor" && p1.GetPlanet() != planet && p2.GetPlanet() != planet && planetrect.PtInRect(MousePos)) {
brush.CreateSolidBrush(RGB(255,0,0));
}
else {
Expand Down Expand Up @@ -533,7 +514,7 @@ void CMainFrame::OnTimer(UINT nIDEvent) {
for(int o=0; o < objects->size(); o++){
ObjectX *missile=(ObjectX*)objects->at(o);
if(missile->getName() == "Missile"){
if(missile->getTime() > 10000002000){
if(missile->getTime() > 1000000000){
animations.push_back(Animation(missile->getPosition(),"Explosion"));
engine->removeObject(missile);
}
Expand Down Expand Up @@ -576,35 +557,6 @@ void CMainFrame::OnTimer(UINT nIDEvent) {
scale=stdscale;
zoom.SetPos(scale);
}
/*if (keys['Z']) {
scale++;
zoom.SetPos(scale);
}
if (keys['X']) {
if (scale != 1) {
scale--;
zoom.SetPos(scale);
}
}
if (keys['C']) {
scale+=1000;
zoom.SetPos(scale);
}
if (keys['V']) {
scale=(scale-1000<1?1:scale-1000);
zoom.SetPos(scale);
}
if (keys['B']) {
scale+=50000;
zoom.SetPos(scale);
}
if (keys['N']) {
scale=(scale-50000<1?1:scale-50000);
zoom.SetPos(scale);
}*/
/*if (keys['X']) {
animations.push_back(Animation(Vector(0,0),"Explosion"));
}*/
if (keys[' ']) {
nuke++;
if (nuke == 3) {
Expand Down Expand Up @@ -744,11 +696,6 @@ void CMainFrame::OnKeyDown(UINT nChar, UINT nRep, UINT nFlags) {
if (winner && nChar == 13) {
OnMenuReset();
}
/*
char text[100];
sprintf(text,"nChar: %d", nChar);
MessageBox(text,"char");
*/
}

void CMainFrame::OnKeyUp(UINT nChar, UINT nRep, UINT nFlags) {
Expand All @@ -773,7 +720,7 @@ void CMainFrame::OnLButtonDown(UINT nFlags, CPoint pt) {
for (int i=0; i < objects->size(); i++) {
ObjectX *planet=(ObjectX*)objects->at(i);
string name=planet->getName();
if (name != "Sun" && name != "Blackhole") {
if (name != "Sun" && name != "Blackhole" && name != "Meteor") {
int planet_x=planet->getPosition().getX()/scale;
int planet_y=-planet->getPosition().getY()/scale;
int radius=planet->getRadius()/scale;
Expand Down Expand Up @@ -829,7 +776,6 @@ void CMainFrame::OnVScroll(UINT nSBCode, UINT nPos, CWnd *pSlider) {
CSliderCtrl *pSld;
pSld=(CSliderCtrl*)pSlider;
scale=pSld->GetPos();
//scale=(scale==1?1:scale);
this->SetFocus();
}

Expand All @@ -851,11 +797,3 @@ BOOL CMainFrame::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt) {
zoom.SetPos(scale);
return 1;
}

void CMainFrame::OnSize() {
/*
CRect window;
GetClientRect(&window);
zoom.GetBuddy()->SetWindowPos(&wndTop,200,200,200,200,SWP_SHOWWINDOW);
*/
}
5 changes: 3 additions & 2 deletions MainFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@ using namespace std;
#define IDC_SLH_ZOOM 300
#define IDC_SLH_SPEED 301

//Vi var tvungen att använda static för att kollisions callback funktionen skulle kunna komma
//åt variablerna
static Physics *engine;
static Player p1;
static Player p2;
static int winner;
static bool start;
static vector<Animation> animations;
static __int64 scale;

class CMainFrame: public CFrameWnd {
private:
int winner;
CMenu menu;
CSliderCtrl zoom, speed;
vector<Object*> *objects;
Expand Down Expand Up @@ -63,7 +65,6 @@ class CMainFrame: public CFrameWnd {
afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CWnd *pSlider);
afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CWnd *pSlider);
afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
afx_msg void OnSize();

DECLARE_MESSAGE_MAP();
};
17 changes: 15 additions & 2 deletions fysik/ObjectX.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "ObjectX.h"

ObjectX::ObjectX(Vector p_position, Vector p_velocity, double p_radius, double p_mass, std::string p_name): Object(p_position, p_velocity, p_radius, p_mass, p_name)
ObjectX::ObjectX(Vector p_position, Vector p_velocity, double p_radius, double p_mass, std::string p_name)
: Object(p_position, p_velocity, p_radius, p_mass, p_name)
{
m_color_r=0;
m_color_g=0;
Expand All @@ -9,7 +10,8 @@ ObjectX::ObjectX(Vector p_position, Vector p_velocity, double p_radius, double p
hp=100;
}

ObjectX::ObjectX(Vector p_position, Vector p_velocity, double p_radius, double p_mass, std::string p_name, unsigned char p_color_r, unsigned char p_color_g, unsigned char p_color_b): Object(p_position, p_velocity, p_radius, p_mass, p_name)
ObjectX::ObjectX(Vector p_position, Vector p_velocity, double p_radius, double p_mass, std::string p_name, unsigned char p_color_r, unsigned char p_color_g, unsigned char p_color_b)
: Object(p_position, p_velocity, p_radius, p_mass, p_name)
{
m_color_r=p_color_r;
m_color_g=p_color_g;
Expand All @@ -18,6 +20,17 @@ ObjectX::ObjectX(Vector p_position, Vector p_velocity, double p_radius, double p
hp=100;
}

ObjectX::ObjectX(Vector p_position, Vector p_velocity, double p_radius, double p_mass, std::string p_name, unsigned char p_color_r, unsigned char p_color_g, unsigned char p_color_b, int p_hp)
: Object(p_position, p_velocity, p_radius, p_mass, p_name)
{
m_color_r=p_color_r;
m_color_g=p_color_g;
m_color_b=p_color_b;
time=0;
hp=p_hp;

}

Vector ObjectX::getVelocity() const
{
return m_velocity;
Expand Down
3 changes: 3 additions & 0 deletions fysik/ObjectX.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "Object.h"
#include "Vector.h"

//Vi extendade deras object class

class ObjectX: public Object
{
protected:
Expand All @@ -16,6 +18,7 @@ class ObjectX: public Object
public:
ObjectX(Vector p_position, Vector p_velocity, double p_radius, double p_mass, std::string p_name);
ObjectX(Vector p_position, Vector p_velocity, double p_radius, double p_mass, std::string p_name, unsigned char p_color_r, unsigned char p_color_g, unsigned char p_color_b);
ObjectX(Vector p_position, Vector p_velocity, double p_radius, double p_mass, std::string p_name, unsigned char p_color_r, unsigned char p_color_g, unsigned char p_color_b, int p_hp);

Vector getVelocity() const;
double getMass() const;
Expand Down
Loading

0 comments on commit 60e6a56

Please sign in to comment.