git repos / blockattack-game

blame: source/code/editor/editorMain.cpp

normal view · raw

89c4a3a6 sago007 2008-08-29 14:32 1
/*
c53e6443 sago007 2012-04-17 11:04 2
===========================================================================
c53e6443 sago007 2012-04-17 11:04 3
blockattack - Block Attack - Rise of the Blocks
c53e6443 sago007 2012-04-17 11:04 4
Copyright (C) 2005-2012 Poul Sander
c53e6443 sago007 2012-04-17 11:04 5
c53e6443 sago007 2012-04-17 11:04 6
This program is free software: you can redistribute it and/or modify
c53e6443 sago007 2012-04-17 11:04 7
it under the terms of the GNU General Public License as published by
c53e6443 sago007 2012-04-17 11:04 8
the Free Software Foundation, either version 2 of the License, or
c53e6443 sago007 2012-04-17 11:04 9
(at your option) any later version.
c53e6443 sago007 2012-04-17 11:04 10
c53e6443 sago007 2012-04-17 11:04 11
This program is distributed in the hope that it will be useful,
c53e6443 sago007 2012-04-17 11:04 12
but WITHOUT ANY WARRANTY; without even the implied warranty of
c53e6443 sago007 2012-04-17 11:04 13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
c53e6443 sago007 2012-04-17 11:04 14
GNU General Public License for more details.
c53e6443 sago007 2012-04-17 11:04 15
c53e6443 sago007 2012-04-17 11:04 16
You should have received a copy of the GNU General Public License
c53e6443 sago007 2012-04-17 11:04 17
along with this program.  If not, see http://www.gnu.org/licenses/
c53e6443 sago007 2012-04-17 11:04 18
c53e6443 sago007 2012-04-17 11:04 19
Source information and contacts persons can be found at
c53e6443 sago007 2012-04-17 11:04 20
http://blockattack.sf.net
c53e6443 sago007 2012-04-17 11:04 21
===========================================================================
89c4a3a6 sago007 2008-08-29 14:32 22
*/
89c4a3a6 sago007 2008-08-29 14:32 23
89c4a3a6 sago007 2008-08-29 14:32 24
#include "editorMain.hpp"
89c4a3a6 sago007 2008-08-29 14:32 25
89c4a3a6 sago007 2008-08-29 14:32 26
EditorInterface ei;
89c4a3a6 sago007 2008-08-29 14:32 27
89c4a3a6 sago007 2008-08-29 14:32 28
//How to write!
89c4a3a6 sago007 2008-08-29 14:32 29
inline void DrawIMG(SDL_Surface *img, SDL_Surface *target, int x, int y)
89c4a3a6 sago007 2008-08-29 14:32 30
{
c53e6443 sago007 2012-04-17 11:04 31
	SDL_Rect dest;
c53e6443 sago007 2012-04-17 11:04 32
	dest.x = x;
c53e6443 sago007 2012-04-17 11:04 33
	dest.y = y;
c53e6443 sago007 2012-04-17 11:04 34
	SDL_BlitSurface(img, NULL, target, &dest);
89c4a3a6 sago007 2008-08-29 14:32 35
}
89c4a3a6 sago007 2008-08-29 14:32 36
c53e6443 sago007 2012-04-17 11:04 37
class createFileButton : public aButton
89c4a3a6 sago007 2008-08-29 14:32 38
{
c53e6443 sago007 2012-04-17 11:04 39
c53e6443 sago007 2012-04-17 11:04 40
public:
c53e6443 sago007 2012-04-17 11:04 41
	createFileButton()
c53e6443 sago007 2012-04-17 11:04 42
	{
c53e6443 sago007 2012-04-17 11:04 43
		aButton::aButton(100,100,bCreateFile);
c53e6443 sago007 2012-04-17 11:04 44
	}
c53e6443 sago007 2012-04-17 11:04 45
c53e6443 sago007 2012-04-17 11:04 46
	void click(int x,int y)
c53e6443 sago007 2012-04-17 11:04 47
	{
c53e6443 sago007 2012-04-17 11:04 48
		if(clicked(x,y))
c53e6443 sago007 2012-04-17 11:04 49
		{
c53e6443 sago007 2012-04-17 11:04 50
			ei.newBoard();
c53e6443 sago007 2012-04-17 11:04 51
		}
c53e6443 sago007 2012-04-17 11:04 52
	}
89c4a3a6 sago007 2008-08-29 14:32 53
};
89c4a3a6 sago007 2008-08-29 14:32 54
c53e6443 sago007 2012-04-17 11:04 55
class deletePuzzleButton : public aButton
89c4a3a6 sago007 2008-08-29 14:32 56
{
c53e6443 sago007 2012-04-17 11:04 57
c53e6443 sago007 2012-04-17 11:04 58
public:
c53e6443 sago007 2012-04-17 11:04 59
	deletePuzzleButton()
c53e6443 sago007 2012-04-17 11:04 60
	{
c53e6443 sago007 2012-04-17 11:04 61
		aButton::aButton(240,100,bDeletePuzzle);
c53e6443 sago007 2012-04-17 11:04 62
	}
c53e6443 sago007 2012-04-17 11:04 63
c53e6443 sago007 2012-04-17 11:04 64
	void click(int x,int y)
c53e6443 sago007 2012-04-17 11:04 65
	{
c53e6443 sago007 2012-04-17 11:04 66
		if(clicked(x,y))
c53e6443 sago007 2012-04-17 11:04 67
		{
c53e6443 sago007 2012-04-17 11:04 68
			ei.deleteBoard();
c53e6443 sago007 2012-04-17 11:04 69
		}
c53e6443 sago007 2012-04-17 11:04 70
	}
89c4a3a6 sago007 2008-08-29 14:32 71
};
89c4a3a6 sago007 2008-08-29 14:32 72
c53e6443 sago007 2012-04-17 11:04 73
class loadFileButton : public aButton
89c4a3a6 sago007 2008-08-29 14:32 74
{
c53e6443 sago007 2012-04-17 11:04 75
c53e6443 sago007 2012-04-17 11:04 76
public:
c53e6443 sago007 2012-04-17 11:04 77
	loadFileButton()
c53e6443 sago007 2012-04-17 11:04 78
	{
c53e6443 sago007 2012-04-17 11:04 79
		aButton::aButton(240,100,bLoadFile);
c53e6443 sago007 2012-04-17 11:04 80
	}
c53e6443 sago007 2012-04-17 11:04 81
c53e6443 sago007 2012-04-17 11:04 82
	void click(int x,int y)
c53e6443 sago007 2012-04-17 11:04 83
	{
c53e6443 sago007 2012-04-17 11:04 84
		if(clicked(x,y))
c53e6443 sago007 2012-04-17 11:04 85
		{
c53e6443 sago007 2012-04-17 11:04 86
			//Thing to load file!
c53e6443 sago007 2012-04-17 11:04 87
		}
c53e6443 sago007 2012-04-17 11:04 88
	}
89c4a3a6 sago007 2008-08-29 14:32 89
};
89c4a3a6 sago007 2008-08-29 14:32 90
c53e6443 sago007 2012-04-17 11:04 91
class moveBackButton : public aButton
89c4a3a6 sago007 2008-08-29 14:32 92
{
c53e6443 sago007 2012-04-17 11:04 93
c53e6443 sago007 2012-04-17 11:04 94
public:
c53e6443 sago007 2012-04-17 11:04 95
	moveBackButton()
c53e6443 sago007 2012-04-17 11:04 96
	{
c53e6443 sago007 2012-04-17 11:04 97
		aButton::aButton(240,100,bMoveBack);
c53e6443 sago007 2012-04-17 11:04 98
	}
c53e6443 sago007 2012-04-17 11:04 99
c53e6443 sago007 2012-04-17 11:04 100
	void click(int x,int y)
c53e6443 sago007 2012-04-17 11:04 101
	{
c53e6443 sago007 2012-04-17 11:04 102
		if(clicked(x,y))
c53e6443 sago007 2012-04-17 11:04 103
		{
c53e6443 sago007 2012-04-17 11:04 104
			ei.moveBoardBack();
c53e6443 sago007 2012-04-17 11:04 105
		}
c53e6443 sago007 2012-04-17 11:04 106
	}
89c4a3a6 sago007 2008-08-29 14:32 107
};
89c4a3a6 sago007 2008-08-29 14:32 108
c53e6443 sago007 2012-04-17 11:04 109
class moveDownButton : public aButton
89c4a3a6 sago007 2008-08-29 14:32 110
{
c53e6443 sago007 2012-04-17 11:04 111
c53e6443 sago007 2012-04-17 11:04 112
public:
c53e6443 sago007 2012-04-17 11:04 113
	moveDownButton()
c53e6443 sago007 2012-04-17 11:04 114
	{
c53e6443 sago007 2012-04-17 11:04 115
		aButton::aButton(240,100,bMoveDown);
c53e6443 sago007 2012-04-17 11:04 116
	}
c53e6443 sago007 2012-04-17 11:04 117
c53e6443 sago007 2012-04-17 11:04 118
	void click(int x,int y)
c53e6443 sago007 2012-04-17 11:04 119
	{
c53e6443 sago007 2012-04-17 11:04 120
		if(clicked(x,y))
c53e6443 sago007 2012-04-17 11:04 121
		{
c53e6443 sago007 2012-04-17 11:04 122
			if(ei.getNumberOfMoves()>0)
c53e6443 sago007 2012-04-17 11:04 123
				ei.setNumberOfMoves(ei.getNumberOfMoves()-1);
c53e6443 sago007 2012-04-17 11:04 124
		}
c53e6443 sago007 2012-04-17 11:04 125
	}
89c4a3a6 sago007 2008-08-29 14:32 126
};
89c4a3a6 sago007 2008-08-29 14:32 127
89c4a3a6 sago007 2008-08-29 14:32 128
theEditor::theEditor()
89c4a3a6 sago007 2008-08-29 14:32 129
{
c53e6443 sago007 2012-04-17 11:04 130
	//This is the constructor
c53e6443 sago007 2012-04-17 11:04 131
	createFileButton cb;
c53e6443 sago007 2012-04-17 11:04 132
	buttons.push_back(cb);
c53e6443 sago007 2012-04-17 11:04 133
	deletePuzzleButton dpb;
c53e6443 sago007 2012-04-17 11:04 134
	buttons.push_back(dpb);
89c4a3a6 sago007 2008-08-29 14:32 135
}
89c4a3a6 sago007 2008-08-29 14:32 136
89c4a3a6 sago007 2008-08-29 14:32 137
void theEditor::drawButtons()
89c4a3a6 sago007 2008-08-29 14:32 138
{
c53e6443 sago007 2012-04-17 11:04 139
	for(int i = 0; i<buttons.size(); i++)
c53e6443 sago007 2012-04-17 11:04 140
	{
c53e6443 sago007 2012-04-17 11:04 141
		(&(buttons[i]))->draw();
c53e6443 sago007 2012-04-17 11:04 142
	}
89c4a3a6 sago007 2008-08-29 14:32 143
}
89c4a3a6 sago007 2008-08-29 14:32 144
89c4a3a6 sago007 2008-08-29 14:32 145
void aButton::click(int x, int y)
89c4a3a6 sago007 2008-08-29 14:32 146
{
c53e6443 sago007 2012-04-17 11:04 147
	cout << "Error: aButtons's click command was executed!" << endl;
89c4a3a6 sago007 2008-08-29 14:32 148
}
89c4a3a6 sago007 2008-08-29 14:32 149
89c4a3a6 sago007 2008-08-29 14:32 150
void aButton::draw()
89c4a3a6 sago007 2008-08-29 14:32 151
{
c53e6443 sago007 2012-04-17 11:04 152
	DrawIMG(label,screen,x,y);
89c4a3a6 sago007 2008-08-29 14:32 153
}
89c4a3a6 sago007 2008-08-29 14:32 154
89c4a3a6 sago007 2008-08-29 14:32 155
void theEditor::click(int x, int y)
89c4a3a6 sago007 2008-08-29 14:32 156
{
c53e6443 sago007 2012-04-17 11:04 157
	for(int i = 0; i<buttons.size(); i++)
c53e6443 sago007 2012-04-17 11:04 158
	{
c53e6443 sago007 2012-04-17 11:04 159
		(&(buttons[i]))->click(x,y);
c53e6443 sago007 2012-04-17 11:04 160
	}
c53e6443 sago007 2012-04-17 11:04 161
}
c53e6443 sago007 2012-04-17 11:04 162
c53e6443 sago007 2012-04-17 11:04 163
int main()
c53e6443 sago007 2012-04-17 11:04 164
{
c53e6443 sago007 2012-04-17 11:04 165
	theEditor te;
c53e6443 sago007 2012-04-17 11:04 166
	te.drawButtons();
1f61db96 sago007 2010-11-15 20:12 167
}