The Bus v0.9: playable version

git-svn-id: svn://kolibrios.org@6984 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2017-09-17 10:38:19 +00:00
parent b9134fd055
commit 54684dffe0
7 changed files with 133 additions and 149 deletions

View File

@ -1,5 +0,0 @@
@del the_bus
@c-- the_bus.c
@rename the_bus.com the_bus
@del warning.txt
@pause

View File

@ -0,0 +1,10 @@
@del lang.h--
@echo #define LANG_ENG 1 >lang.h--
@del the_bus
@cls
@c-- the_bus.c
@pause
@rename the_bus.com the_bus
@del warning.txt
@del lang.h--

View File

@ -0,0 +1,10 @@
@del lang.h--
@echo #define LANG_RUS 1 >lang.h--
@del the_bus
@cls
@c-- the_bus.c
@pause
@rename the_bus.com the_bus
@del warning.txt
@del lang.h--

View File

@ -1,29 +0,0 @@
void DrawScaledBar(dword x,y,w,h,col) {
DrawBar(
x*SCALE,
y*SCALE,
w*SCALE,
h*SCALE,
col
);
}
void DrawScaledImage(dword image_pointer,x,y,w,h,offx,offy) {
img_draw stdcall (
image_pointer,
x*SCALE,
y*SCALE,
w*SCALE,
h*SCALE,
offx*SCALE,
offy*SCALE
);
}
void WriteScaledText(dword x,y,font,color,text) {
WriteText(
x*SCALE,
y*SCALE,
font + SCALE,
color,
text
);
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.4 KiB

After

Width:  |  Height:  |  Size: 7.6 KiB

View File

@ -6,6 +6,10 @@ D O N K E Y
Copyright (C) 2008 O.Bogomaz Copyright (C) 2008 O.Bogomaz
*/ */
#ifndef AUTOBUILD
#include "lang.h--"
#endif
#define MEMSIZE 1024 * 60; #define MEMSIZE 1024 * 60;
#include "..\lib\kolibri.h" #include "..\lib\kolibri.h"
@ -15,18 +19,14 @@ Copyright (C) 2008 O.Bogomaz
#include "..\lib\obj\libimg_lib.h" #include "..\lib\obj\libimg_lib.h"
#include "..\lib\patterns\libimg_load_skin.h" #include "..\lib\patterns\libimg_load_skin.h"
#define SCALE 2
#include "draw_scalled.h"
libimg_image menu; libimg_image menu;
libimg_image road; libimg_image road;
libimg_image objects; libimg_image objects;
int lives=0, level=0, score=0; int lives=0, level=0, score=0;
int don_x, don_y, don_h, don_w=39, don_type, don_image_y; int don_x, don_y, don_h, don_w=68, don_type, don_image_y, don_step_y, don_step_y_default=3;
int don_h_mas[8] = { 18,36,18,37,12,32,24,37 }; int don_h_mas[8] = { 36,72,36,74,24,64,48,74 };
int bus_x, bus_w=21, bus_y=145, bus_h=44; int bus_x, bus_w=42, bus_y, bus_h=88, bus_y_default=290;
#define SCR_MENU_MAIN 1 #define SCR_MENU_MAIN 1
#define SCR_GAME 2 #define SCR_GAME 2
@ -34,8 +34,8 @@ int bus_x, bus_w=21, bus_y=145, bus_h=44;
#define RAND -1 #define RAND -1
#define WIN_X 258 #define WIN_X 516
#define WIN_Y 191 #define WIN_Y 382
int screen_type=SCR_MENU_MAIN; int screen_type=SCR_MENU_MAIN;
@ -43,7 +43,7 @@ int screen_type=SCR_MENU_MAIN;
int active_menu_item=0; int active_menu_item=0;
char *ITEMS_LIST[]={ char *MENU_LIST[]={
"New game", "New game",
"Control keys", "Control keys",
"About", "About",
@ -64,28 +64,24 @@ void DrawObstacle(signed int x, y) {
don_offset_y = don_image_y - y; don_offset_y = don_image_y - y;
y = 0; y = 0;
} }
if (y>=don_step_y) DrawBar(x, y-don_step_y, don_w, don_step_y, COLOR_ROAD); //Fill donkey old parts
debugval("y", y); if (image_h>0) DrawLibImage(objects.image, x, y, don_w, image_h, 0, don_offset_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(objects.image, x, y, bus_w, bus_h, 0, 222); } void DrawBus(dword x, y) { DrawLibImage(objects.image, x, y, bus_w, bus_h, 0, 444); }
void DrawBoom(dword x, y) { DrawScaledImage(objects.image, x, y, 39, 33, 0, 268); } void DrawBoom(dword x, y) { DrawLibImage(objects.image, x, y, 78, 66, 0, 536); }
void DrawHighway() { DrawScaledImage(road.image, 0,0, WIN_X, WIN_Y, 0, 0); } void DrawHighway() { DrawLibImage(road.image, 0,0, WIN_X, WIN_Y, 0, 0); }
void DrawMenuBackground() { DrawScaledImage(menu.image, 0, 0, WIN_X, WIN_Y, 0, 0); } void DrawMenuBackground() { DrawLibImage(menu.image, 0, 0, WIN_X, WIN_Y, 0, 0); }
void main() void main()
{ {
randomize(); randomize();
GetNewObstacle(RAND); StartNewGame();
load_dll(libio, #libio_init,1); load_dll(libio, #libio_init,1);
load_dll(libimg, #libimg_init,1); load_dll(libimg, #libimg_init,1);
Libimg_LoadImage(#menu, "/sys/fonts/menu.png"); Libimg_LoadImage(#menu, "menu.png");
Libimg_LoadImage(#road, "/sys/fonts/road.png"); Libimg_LoadImage(#road, "road.png");
Libimg_LoadImage(#objects, "/sys/fonts/objects.png"); Libimg_LoadImage(#objects, "objects.png");
loop() loop()
{ {
@ -114,30 +110,28 @@ void main()
{ {
if (active_menu_item==0) if (active_menu_item==0)
{ {
lives=3; StartNewGame();
level=0;
score=0;
SetScreen(SCR_GAME); 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==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.4 Alpha\n\nAuthor: Leency\nMenu image from Freepik.com'tI"); if (active_menu_item==2) notify("'The Bus\nVersion v0.9\nAuthor: Leency\nMenu image from Freepik.com'tI");
if (active_menu_item==3) ExitProcess(); if (active_menu_item==3) ExitProcess();
} }
if (key_scancode == SCAN_CODE_SPACE) && (screen_type==SCR_GAME) if (key_scancode == SCAN_CODE_SPACE) && (screen_type==SCR_GAME)
{ {
DrawScaledBar(bus_x*40+100, bus_y, bus_w, bus_h+1, COLOR_ROAD); DrawBar(bus_x*80+200, bus_y, bus_w, bus_h+1, COLOR_ROAD);
if (bus_x==1) bus_x=0; else bus_x=1; if (bus_x==1) bus_x=0; else bus_x=1;
} }
if (key_scancode == SCAN_CODE_LEFT) && (screen_type==SCR_GAME) if (key_scancode == SCAN_CODE_LEFT) && (screen_type==SCR_GAME)
{ {
if (bus_x==0) break; if (bus_x==0) break;
DrawScaledBar(bus_x*40+100, bus_y, bus_w, bus_h+1, COLOR_ROAD); DrawBar(bus_x*80+200, bus_y, bus_w, bus_h+1, COLOR_ROAD);
bus_x=0; bus_x=0;
} }
if (key_scancode == SCAN_CODE_RIGHT) && (screen_type==SCR_GAME) if (key_scancode == SCAN_CODE_RIGHT) && (screen_type==SCR_GAME)
{ {
if (bus_x==1) break; if (bus_x==1) break;
DrawScaledBar(bus_x*40+100, bus_y, bus_w, bus_h+1, COLOR_ROAD); DrawBar(bus_x*80+200, bus_y, bus_w, bus_h+1, COLOR_ROAD);
bus_x=1; bus_x=1;
} }
if (key_scancode == SCAN_CODE_KEY_P) if (key_scancode == SCAN_CODE_KEY_P)
@ -149,7 +143,7 @@ void main()
break; break;
case evReDraw: case evReDraw:
DefineAndDrawWindow(250,150,WIN_X * SCALE-1+10,WIN_Y * SCALE-1+skin_height+5,0x74,0,"The Bus",0); DefineAndDrawWindow(250,150,WIN_X-1,WIN_Y-1,0x01,0,"The Bus",0); //0x74 is also possible if you fix bottom border
DrawScreen(); DrawScreen();
break; break;
@ -158,16 +152,67 @@ void main()
break; break;
default: default:
if (screen_type==SCR_GAME) DrawRoad(); if (screen_type==SCR_GAME)
{
if ((don_x == bus_x)&&(don_y + don_h > bus_y )&&(don_y < bus_y + don_h )) {
lives--;
DrawBus(bus_x*80+200,bus_y);
DrawBoom(bus_x*80+180,302);
pause(150);
GetNewObstacle(RAND);
DrawScreen();
}
if (lives==0) {
DrawGameOverMessage();
break; break;
} }
don_y += don_step_y;
if (don_y - don_step_y >= WIN_Y)
{
GetNewObstacle(RAND);
score++;
bus_y -= don_step_y+1;
DrawBar(bus_x*80+200, bus_y+bus_h, bus_w, don_step_y, COLOR_ROAD);
WriteScore();
}
if (score) && (score % 15 == 0)
{
score++;
NewLevel();
DrawScreen();
don_step_y++;
}
DrawRoad();
}
}
} }
} }
void NewLevel()
{
level++;
bus_y = bus_y_default;
}
void StartNewGame()
{
lives=3;
level=0;
score=0;
bus_y = bus_y_default;
don_step_y = don_step_y_default;
GetNewObstacle(RAND);
}
void WriteScore() { void WriteScore() {
DrawScaledImage(road.image, 10, 83, 60, 12, 10, 82); DrawLibImage(road.image, 20, 166, 120, 24, 20, 164);
WriteScaledText(10, 70, 0x80, 0xFFFFFF, "Score"); WriteText(20, 140, 0x81, 0xFFFFFF, "Score");
WriteScaledText(10, 83, 0x80, 0xFFFFFF, itoa(score)); WriteText(20, 166, 0x81, 0xFFFFFF, itoa(score));
} }
void SetScreen(dword _screen_type) { void SetScreen(dword _screen_type) {
@ -181,35 +226,23 @@ void DrawScreen()
if (screen_type==SCR_MENU_MAIN) if (screen_type==SCR_MENU_MAIN)
{ {
DrawMenuBackground(); DrawMenuBackground();
WriteScaledText(10, 10, 0x80, 0xE8783F, "TAKE THE CHILDREN HOME"); WriteTextB(20, 20, 0x82, 0xE8783F, "THE BUS");
$add ebx, 2 << 16
$int 64
DrawMenuList(); DrawMenuList();
} }
if (screen_type==SCR_GAME) || (screen_type==SCR_PAUSE) if (screen_type==SCR_GAME) || (screen_type==SCR_PAUSE)
{ {
DrawHighway(); DrawHighway();
WriteScaledText(10, 10, 0x80, 0xFFFFFF, "Lives"); WriteText(20, 20, 0x81, 0xFFFFFF, "Lives");
WriteScaledText(10, 23, 0x80, 0xFFFFFF, itoa(lives)); WriteText(20, 46, 0x81, 0xFFFFFF, itoa(lives));
WriteScaledText(10, 40, 0x80, 0xFFFFFF, "Level"); WriteText(20, 80, 0x81, 0xFFFFFF, "Level");
WriteScaledText(10, 53, 0x80, 0xFFFFFF, itoa(level)); WriteText(20, 106, 0x81, 0xFFFFFF, itoa(level));
WriteScore(); WriteScore();
DrawRoad(); DrawRoad();
if (screen_type==SCR_PAUSE) { if (screen_type==SCR_PAUSE) {
DrawScaledBar(0,0,70,30,0xFF0000); DrawBar(0,0,140,60,0xFF0000);
WriteScaledText(5,7,0x81,0xFFFfff,"PAUSE"); WriteText(10,14,0x83,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);
}
}
*/
} }
@ -223,95 +256,60 @@ void DrawMenuItem(int item_n, text_n)
{ {
dword color; dword color;
if (active_menu_item==item_n) color = 0xFF0000; else color = 0xFFffff; if (active_menu_item==item_n) color = 0xFF0000; else color = 0xFFffff;
WriteScaledText(10+1, item_n*28+48+1, 0x80, 0xAAAaaa, ITEMS_LIST[text_n]); WriteText(20+2, item_n*56+116+2, 0x81, 0xAAAaaa, MENU_LIST[text_n]);
WriteScaledText(10, item_n*28+48, 0x80, color, ITEMS_LIST[text_n]); WriteText(20, item_n*56+116, 0x81, color, MENU_LIST[text_n]);
} }
void DrawGameOverMessage() void DrawGameOverMessage()
{ {
DrawScaledBar(0, 0, WIN_X, WIN_Y, 0xF3E1BD); DrawBar(0, 0, WIN_X, WIN_Y, 0xF3E1BD);
WriteScaledText(20, 20, 0x80, 0xA48C74, "GAME OVER"); WriteText(40, 40, 0x81, 0xA48C74, "GAME OVER");
WriteScaledText(20, 40, 0x80, 0xA48C74, "FINAL SCORE"); WriteText(40, 75, 0x81, 0xA48C74, "FINAL SCORE");
WriteScaledText(20, 70, 0x84, 0xA48C74, itoa(score)); WriteTextB(40, 140, 0x85, 0xA48C74, itoa(score));
$add ecx, 2 << 16
$int 64
pause(350); pause(350);
active_menu_item=0; active_menu_item=0;
SetScreen(SCR_MENU_MAIN); SetScreen(SCR_MENU_MAIN);
} }
void DrawAccident()
{
DrawBus(bus_x*40+100,bus_y);
DrawBoom(bus_x*40+90,151);
pause(150);
lives--;
don_y = -don_h;
DrawScreen();
if (lives>0) DrawScaledBar(bus_x*40+90, 147-17, 39, 45+23, COLOR_ROAD);
}
void GetNewObstacle(int N) void GetNewObstacle(int N)
{ {
int i; int i;
don_x = random(2); don_x = random(2);
if (N==RAND) { if (N==RAND) don_type = random(7); else don_type = N;
don_type = random(7);
}
else {
don_type = N;
}
don_h = don_h_mas[don_type]; don_h = don_h_mas[don_type];
don_y = -don_h+1; don_y = -don_h;
don_image_y = 0; don_image_y = 0;
for (i = 0; i < don_type; i++) //calculate image y offset for current obstacle for (i = 0; i < don_type; i++) don_image_y += don_h_mas[i]+2; //calculate image y offset for current obstacle
{
don_image_y += don_h_mas[i]+1;
}
} }
#define LINE_LENGTH 10 #define LINE_LENGTH 10
void DrawRoad() int line_y=0;
void DrawLineSeparator()
{ {
int y, line_y; int y;
if (screen_type == SCR_GAME) line_y += don_step_y;
if ((don_x == bus_x)&&(don_y + don_h > bus_y )&&(don_y < bus_y + don_h )) DrawAccident();
if (lives==0) {
DrawGameOverMessage();
return;
}
if (screen_type != SCR_PAUSE)
{
line_y+=2;
don_y+=2;
}
//the beginning of the white dashed line between two roadways //the beginning of the white dashed line between two roadways
if (line_y>=20) { if (line_y>=20) {
line_y=0; line_y=0;
} }
else else
{ {
DrawScaledBar(129, 0, 1, line_y, COLOR_ROAD); DrawBar(258, 0, 2, line_y, COLOR_ROAD);
DrawScaledBar(129, 0, 1, line_y-LINE_LENGTH, 0xDDE9F2); DrawBar(258, 0, 2, line_y-LINE_LENGTH, 0xDDE9F2);
} }
for (y=0; y<WIN_Y-20; 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); DrawBar(258, line_y+y, 2, LINE_LENGTH, 0xDDE9F2);
DrawScaledBar(129, line_y+y+LINE_LENGTH, 1, LINE_LENGTH, COLOR_ROAD); DrawBar(258, line_y+y+LINE_LENGTH, 2, LINE_LENGTH, COLOR_ROAD);
} }
if (don_y >= WIN_Y) }
{
GetNewObstacle(RAND); void DrawRoad()
score++; {
WriteScore(); DrawLineSeparator();
} DrawObstacle(don_w+10*don_x+186,don_y);
DrawScaledBar(don_x*don_w+93, don_y-2, 30, 2, COLOR_ROAD); //Fill donkey old parts DrawBus(bus_x*80+200,bus_y);
DrawObstacle(don_x*don_w+90,don_y);
DrawBus(bus_x*40+100,147);
} }