Subversion Repositories Kolibri OS

Compare Revisions

No changes between revisions

Regard whitespace Rev 6975 → Rev 6976

/programs/cmm/the_bus/objects.png
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/programs/cmm/the_bus/road.png
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/programs/cmm/the_bus/the_bus.c
21,18 → 21,21
 
libimg_image menu;
libimg_image road;
libimg_image objects;
 
int lives=0, level=0, score=0;
int don_x, don_y, don_h=40, don_type;
int bus_x, bus_y=147;
int don_x, don_y, don_h, don_w=39, don_type, don_image_y;
int don_h_mas[8] = { 18,36,18,37,12,32,24,37 };
int bus_x, bus_w=21, bus_y=145, bus_h=44;
 
#define SCR_MENU_MAIN 1
#define SCR_GAME 2
#define SCR_PAUSE 3
 
#define RAND -1
 
#define WIN_X 258 * SCALE
#define WIN_Y 191 * SCALE
#define WIN_X 258
#define WIN_Y 191
 
int screen_type=SCR_MENU_MAIN;
 
48,43 → 51,41
0};
 
 
//actually it has to be named DrawObstacle(), but I like Donkey more :)
void DrawDonkey(signed int x, y) {
int don_offset_x;
void DrawObstacle(signed int x, y) {
int don_offset_y;
int image_h;
 
if (don_type<4) {
don_offset_y=0;
don_offset_x=don_type*40;
if (y >= 0) {
image_h = don_h;
don_offset_y = don_image_y;
}
else {
don_offset_y = don_h + 1;
don_offset_x=don_type-3*40;
}
 
image_h = don_h;
if (y < 0) {
image_h = don_h + y+1;
don_offset_y = don_h + y;
image_h = don_h + y;
don_offset_y = don_image_y - y;
y = 0;
}
 
DrawScaledImage(road.image, x, y, 39, image_h, don_offset_x, don_offset_y);
debugval("y", y);
debugval("don_h", don_h);
debugval("image_h", image_h);
debugval("don_offset_y", don_offset_y);
DrawScaledImage(objects.image, x, y, don_w, image_h, 0, don_offset_y);
}
void DrawBus(dword x, y) { DrawScaledImage(road.image, x, y, 21, 45, 237, 0); }
void DrawBoom(dword x, y) { DrawScaledImage(road.image, x, y, 39, 34, 208, 47); }
void DrawHighway() { DrawScaledImage(road.image, 0,0, WIN_X, WIN_Y, 0, 82); }
void DrawBus(dword x, y) { DrawScaledImage(objects.image, x, y, bus_w, bus_h, 0, 222); }
void DrawBoom(dword x, y) { DrawScaledImage(objects.image, x, y, 39, 33, 0, 268); }
void DrawHighway() { DrawScaledImage(road.image, 0,0, WIN_X, WIN_Y, 0, 0); }
void DrawMenuBackground() { DrawScaledImage(menu.image, 0, 0, WIN_X, WIN_Y, 0, 0); }
 
void main()
{
randomize();
GetNewObstacle(RAND);
 
load_dll(libio, #libio_init,1);
load_dll(libimg, #libimg_init,1);
Libimg_LoadImage(#menu, "/sys/fonts/home2x.png");
Libimg_LoadImage(#road, "/sys/fonts/busimg2x.png");
Libimg_LoadImage(#menu, "/sys/fonts/menu.png");
Libimg_LoadImage(#road, "/sys/fonts/road.png");
Libimg_LoadImage(#objects, "/sys/fonts/objects.png");
loop()
{
119,24 → 120,24
SetScreen(SCR_GAME);
}
if (active_menu_item==1) notify("'The Bus\nControl keys:\nLeft, Right, Space\nPress P key for pause'tI");
if (active_menu_item==2) notify("'The Bus\nVersion v0.2 Alpha\n\nAuthor: Leency\nMenu image from Freepik.com'tI");
if (active_menu_item==2) notify("'The Bus\nVersion v0.4 Alpha\n\nAuthor: Leency\nMenu image from Freepik.com'tI");
if (active_menu_item==3) ExitProcess();
}
if (key_scancode == SCAN_CODE_SPACE) && (screen_type==SCR_GAME)
{
DrawScaledBar(bus_x*40+100,147, 21,45, COLOR_ROAD);
DrawScaledBar(bus_x*40+100, bus_y, bus_w, bus_h+1, COLOR_ROAD);
if (bus_x==1) bus_x=0; else bus_x=1;
}
if (key_scancode == SCAN_CODE_LEFT) && (screen_type==SCR_GAME)
{
if (bus_x==0) break;
DrawScaledBar(bus_x*40+100,147, 21,45, COLOR_ROAD);
DrawScaledBar(bus_x*40+100, bus_y, bus_w, bus_h+1, COLOR_ROAD);
bus_x=0;
}
if (key_scancode == SCAN_CODE_RIGHT) && (screen_type==SCR_GAME)
{
if (bus_x==1) break;
DrawScaledBar(bus_x*40+100,147, 21,45, COLOR_ROAD);
DrawScaledBar(bus_x*40+100, bus_y, bus_w, bus_h+1, COLOR_ROAD);
bus_x=1;
}
if (key_scancode == SCAN_CODE_KEY_P)
148,7 → 149,7
break;
case evReDraw:
DefineAndDrawWindow(250,150,WIN_X-1+10,WIN_Y-1+skin_height+7,0x74,0,"The Bus",0);
DefineAndDrawWindow(250,150,WIN_X * SCALE-1+10,WIN_Y * SCALE-1+skin_height+5,0x74,0,"The Bus",0);
DrawScreen();
break;
164,7 → 165,7
}
 
void WriteScore() {
DrawScaledImage(road.image, 10, 83, 60, 12, 10, 83+82);
DrawScaledImage(road.image, 10, 83, 60, 12, 10, 82);
WriteScaledText(10, 70, 0x80, 0xFFFFFF, "Score");
WriteScaledText(10, 83, 0x80, 0xFFFFFF, itoa(score));
}
176,6 → 177,7
 
void DrawScreen()
{
int i;
if (screen_type==SCR_MENU_MAIN)
{
DrawMenuBackground();
198,7 → 200,17
WriteScaledText(5,7,0x81,0xFFFfff,"PAUSE");
}
}
/*
if (screen_type==SCR_PAUSE)
{
for (i = 0; i < 8; i++) //calculate image y offset for current obstacle
{
GetNewObstacle(i);
DrawObstacle(don_w+1*i, 10);
}
}
*/
}
 
 
void DrawMenuList()
227,13 → 239,12
pause(350);
active_menu_item=0;
SetScreen(SCR_MENU_MAIN);
return;
}
 
void DrawAccident()
{
DrawBus(bus_x*40+100,bus_y);
DrawBoom(bus_x*40+90,152);
DrawBoom(bus_x*40+90,151);
pause(150);
lives--;
don_y = -don_h;
241,12 → 252,31
if (lives>0) DrawScaledBar(bus_x*40+90, 147-17, 39, 45+23, COLOR_ROAD);
}
 
void GetNewObstacle(int N)
{
int i;
don_x = random(2);
if (N==RAND) {
don_type = random(7);
}
else {
don_type = N;
}
don_h = don_h_mas[don_type];
don_y = -don_h+1;
don_image_y = 0;
for (i = 0; i < don_type; i++) //calculate image y offset for current obstacle
{
don_image_y += don_h_mas[i]+1;
}
}
 
#define LINE_LENGTH 10
void DrawRoad()
{
byte y,line_y;
int y, line_y;
if ((don_x == bus_x)&&(don_y + don_h > bus_y )&&(don_y + don_h < bus_y )) DrawAccident();
if ((don_x == bus_x)&&(don_y + don_h > bus_y )&&(don_y < bus_y + don_h )) DrawAccident();
if (lives==0) {
DrawGameOverMessage();
268,22 → 298,20
DrawScaledBar(129, 0, 1, line_y, COLOR_ROAD);
DrawScaledBar(129, 0, 1, line_y-LINE_LENGTH, 0xDDE9F2);
}
for (y=0; y<190; y+=20) //white dashed line between two roadways
for (y=0; y<WIN_Y-20; y+=20) //white dashed line between two roadways
{
DrawScaledBar(129, line_y+y, 1, LINE_LENGTH, 0xDDE9F2);
DrawScaledBar(129, line_y+y+LINE_LENGTH, 1, LINE_LENGTH, COLOR_ROAD);
}
if (don_y>=210)
if (don_y >= WIN_Y)
{
don_x = random(2);
don_y = -don_h;
don_type = random(7);
GetNewObstacle(RAND);
score++;
WriteScore();
}
DrawScaledBar(don_x*don_h+93, don_y-2, 30, 2, COLOR_ROAD); //Fill donkey old parts
DrawDonkey(don_x*don_h+90,don_y);
DrawBus(bus_x*don_h+100,147);
DrawScaledBar(don_x*don_w+93, don_y-2, 30, 2, COLOR_ROAD); //Fill donkey old parts
DrawObstacle(don_x*don_w+90,don_y);
DrawBus(bus_x*40+100,147);
}