Tweak to mission2 movement, map editor

This commit is contained in:
stevenhowes
2021-04-06 19:52:01 +01:00
parent bf2cc9e635
commit 436fea16e4
6 changed files with 422 additions and 38 deletions
Binary file not shown.
Binary file not shown.
+18 -17
View File
@@ -3,42 +3,43 @@
# Toolflags:
CCflags = -c -depend !Depend -IC: -throwback -w
C++flags = -c -depend !Depend -IC: -throwback
Linkflags = -aif -o $@
ObjAsmflags = -throwback -NoCache -depend !Depend
CMHGflags =
LibFileflags = -c -o $@
Squeezeflags = -o $@
# Final targets:
@.!RunImage: @.o.CTheEscape @.o.Graphics @.o.Sound @.o.Input @.o.Intro @.o.Mission1 @.o.Mission2 C:o.stubs
Link $(Linkflags) @.o.CTheEscape @.o.Graphics @.o.Sound @.o.Input @.o.Intro @.o.Mission1 @.o.Mission2 C:o.stubs
@.!RunImage: @.o.CTheEscape @.o.Graphics @.o.Sound @.o.Input @.o.Intro \
@.o.Mission1 @.o.Mission2 C:o.stubs
Link $(Linkflags) @.o.CTheEscape @.o.Graphics @.o.Sound @.o.Input \
@.o.Intro @.o.Mission1 @.o.Mission2 C:o.stubs
# User-editable dependencies:
# Static dependencies:
@.o.CTheEscape: @.c.CTheEscape
cc $(ccflags) -o @.o.CTheEscape @.c.CTheEscape
cc $(ccflags) -o @.o.CTheEscape @.c.CTheEscape
@.o.MapEdit: @.c.MapEdit
cc $(ccflags) -o @.o.MapEdit @.c.MapEdit
@.o.Graphics: @.c.Graphics
cc $(ccflags) -o @.o.Graphics @.c.Graphics
cc $(ccflags) -o @.o.Graphics @.c.Graphics
@.o.Sound: @.c.Sound
cc $(ccflags) -o @.o.Sound @.c.Sound
cc $(ccflags) -o @.o.Sound @.c.Sound
@.o.Input: @.c.Input
cc $(ccflags) -o @.o.Input @.c.Input
cc $(ccflags) -o @.o.Input @.c.Input
@.o.Intro: @.c.Intro
cc $(ccflags) -o @.o.Intro @.c.Intro
cc $(ccflags) -o @.o.Intro @.c.Intro
@.o.Mission1: @.c.Mission1
cc $(ccflags) -o @.o.Mission1 @.c.Mission1
cc $(ccflags) -o @.o.Mission1 @.c.Mission1
@.o.Mission2: @.c.Mission2
cc $(ccflags) -o @.o.Mission2 @.c.Mission2
cc $(ccflags) -o @.o.Mission2 @.c.Mission2
# Dynamic dependencies:
o.CTheEscape: c.CTheEscape
o.CTheEscape: C:h.swis
o.CTheEscape: C:h.kernel
o.CTheEscape: C:h.kernel
o.CTheEscape: h.Sound
o.CTheEscape: h.Graphics
o.CTheEscape: c.CTheEscape
o.CTheEscape: C:h.swis
o.CTheEscape: C:h.kernel
+67
View File
@@ -0,0 +1,67 @@
# Project: TheEscTools
# Toolflags:
CCflags = -c -depend !Depend -IC: -throwback -w
C++flags = -c -depend !Depend -IC: -throwback
Linkflags = -aif -o $@
ObjAsmflags = -throwback -NoCache -depend !Depend
CMHGflags =
LibFileflags = -c -o $@
Squeezeflags = -o $@
# Final targets:
@.!MapEdit: @.o.MapEdit @.o.Graphics @.o.Input \
C:o.stubs
Link $(Linkflags) @.o.MapEdit @.o.Graphics @.o.Input \
C:o.stubs
# User-editable dependencies:
# Static dependencies:
@.o.MapEdit: @.c.MapEdit
cc $(ccflags) -o @.o.MapEdit @.c.MapEdit
@.o.Graphics: @.c.Graphics
cc $(ccflags) -o @.o.Graphics @.c.Graphics
@.o.Input: @.c.Input
cc $(ccflags) -o @.o.Input @.c.Input
# Dynamic dependencies:
o.CTheEscape: c.CTheEscape
o.CTheEscape: C:h.swis
o.CTheEscape: C:h.kernel
o.CTheEscape: C:h.kernel
o.CTheEscape: h.Sound
o.CTheEscape: h.Graphics
o.Sound: c.Sound
o.Sound: C:h.swis
o.Sound: C:h.kernel
o.Sound: C:h.kernel
o.Sound: h.Sound
o.Intro: c.Intro
o.Intro: h.Graphics
o.Mission1: c.Mission1
o.Mission1: h.Graphics
o.Mission2: c.Mission2
o.Mission2: h.Graphics
o.Mission2: C:h.swis
o.Mission2: C:h.kernel
o.Mission2: C:h.kernel
o.Graphics: c.Graphics
o.Graphics: C:h.swis
o.Graphics: C:h.kernel
o.Graphics: C:h.kernel
o.Input: c.Input
o.Input: C:h.swis
o.Input: C:h.kernel
o.Input: C:h.kernel
o.MapEdit: c.MapEdit
o.MapEdit: C:h.swis
o.MapEdit: C:h.kernel
o.MapEdit: C:h.kernel
o.MapEdit: h.Sound
o.MapEdit: h.Graphics
+323
View File
@@ -0,0 +1,323 @@
#include <stdio.h>
#include "swis.h"
#include <kernel.h>
#include <time.h>
#include "Sound.h"
#include "Graphics.h"
/********************************************\
Slightly hacked up 'Mission2' as a map editor
\********************************************/
extern int tick;
extern int lasttick;
extern int screen;
#define TILESX 10
#define TILESY 10
// SWI Registers
_kernel_swi_regs inreg;
_kernel_swi_regs outreg;
// Sprite buffer
unsigned char *buffer;
unsigned char *fontbuffer;
unsigned char *tilebuffer;
extern int screen;
extern struct CompositionElement composition[128];
extern int current_element;
int lastprofile = 0;
int tick = 0;
int lasttick = 0;
extern int screen;
extern int game1_tick();
extern void game1_setup();
extern void screen_nobuffer();
// map[0] is the 'master', [1] and [2] represents what is currently
// believed to be displayed in the corresponding (+1) screen buffer
// and we run a compare to see if re-drawing is needed. 0xFF is used
// for a re-draw being required (so it's set on the tile under the player
unsigned char map[3][TILESX][TILESY];
unsigned char fullmap[10000];
char tilenamebuffer[4];
char textbuffer[63];
struct EntityLocation_s {
short signed int X,Y;
};
int readmodkey = 0;
struct TilePlayer_s {
struct EntityLocation_s location;
struct EntityLocation_s hitbox_bl;
struct EntityLocation_s hitbox_tr;
struct EntityLocation_s mapoffset;
struct EntityLocation_s localtile;
int rawtile;
};
struct TilePlayer_s TilePlayer;
void game2_loadmap(char* filename)
{
int length;
// Attempt to get file info
inreg.r[0] = 13;
inreg.r[1] = (int) filename;
_kernel_swi(OS_File,&inreg,&outreg);
// Length will be in R4 if it exists
length = outreg.r[4];
if(length > sizeof(fullmap))
{
// TODO: Work out why real machine doesn't appear to read size and gives object type 19
/*screen_nobuffer();
printf("Map exceeds %d bytes (%d bytes) Object Type %d",sizeof(fullmap),length,outreg.r[0]);
exit(0);*/
}
// Attempt to get file info
inreg.r[0] = 16;
inreg.r[1] = (int) filename;
inreg.r[2] = (int) fullmap;
inreg.r[3] = 0;
_kernel_swi(OS_File,&inreg,&outreg);
}
void game2_fillmap(int xoffset, int yoffset)
{
memcpy(map[0][0],fullmap+yoffset+(xoffset*100),10);
memcpy(map[0][1],fullmap+yoffset+(xoffset*100)+100,10);
memcpy(map[0][2],fullmap+yoffset+(xoffset*100)+200,10);
memcpy(map[0][3],fullmap+yoffset+(xoffset*100)+300,10);
memcpy(map[0][4],fullmap+yoffset+(xoffset*100)+400,10);
memcpy(map[0][5],fullmap+yoffset+(xoffset*100)+500,10);
memcpy(map[0][6],fullmap+yoffset+(xoffset*100)+600,10);
memcpy(map[0][7],fullmap+yoffset+(xoffset*100)+700,10);
memcpy(map[0][8],fullmap+yoffset+(xoffset*100)+800,10);
memcpy(map[0][9],fullmap+yoffset+(xoffset*100)+900,10);
}
void game2_setup()
{
screen_flipbuffer();
screen_clear();
screen_flipbuffer();
screen_clear();
TilePlayer.location.X = 100;
TilePlayer.location.Y = 100;
TilePlayer.hitbox_bl.X = 0;
TilePlayer.hitbox_bl.Y = 0;
TilePlayer.hitbox_tr.X = 60;
TilePlayer.hitbox_tr.Y = 50;
memset(map[0],0xFF,100);
memset(map[1],0xFF,100);
memset(map[2],0xFF,100);
game2_loadmap("mission2");
game2_fillmap(TilePlayer.mapoffset.X,TilePlayer.mapoffset.Y);
}
void game2_tick_input()
{
int x,y;
// Up arrow
if(input_readkey(57))
{
TilePlayer.location.Y += 3 * (tick - lasttick);
if(TilePlayer.location.Y > (950))
{
TilePlayer.location.Y = 100;
TilePlayer.mapoffset.Y += 10;
}
}
// Down arrow
if(input_readkey(41))
{
TilePlayer.location.Y -= 3 * (tick - lasttick);
if(TilePlayer.location.Y < (10))
{
TilePlayer.location.Y = 900;
TilePlayer.mapoffset.Y -= 10;
}
}
// Right arrow
if(input_readkey(121))
{
TilePlayer.location.X += 3 * (tick - lasttick);
if(TilePlayer.location.X > (950))
{
TilePlayer.location.X = 100;
TilePlayer.mapoffset.X += 10;
}
}
// Left arrow
if(input_readkey(25))
{
TilePlayer.location.X -= 3 * (tick - lasttick);
if(TilePlayer.location.X < (10))
{
TilePlayer.location.X = 900;
TilePlayer.mapoffset.X -= 10;
}
}
// Right Pointy
if(input_readkey(103))
{
if(tick > readmodkey)
{
fullmap[TilePlayer.rawtile] = fullmap[TilePlayer.rawtile] + 1;
readmodkey = tick + 10;
}
}
// Left Pointy
if(input_readkey(102))
{
if(tick > readmodkey)
{
fullmap[TilePlayer.rawtile] = fullmap[TilePlayer.rawtile] - 1;
readmodkey = tick + 10;
}
}
}
int game2_tick()
{
int x;
int y;
int udt = 0;
lasttick = tick;
tick = clock();
screen_flipbuffer();
if(1)
{
game2_fillmap(TilePlayer.mapoffset.X,TilePlayer.mapoffset.Y);
for(x = 0; x < TILESX; x++)
{
for(y = 0; y < TILESY; y++)
{
if(game_hitbox_collide(
(TilePlayer.location.X + TilePlayer.hitbox_bl.X),(TilePlayer.location.Y + TilePlayer.hitbox_bl.Y),
(TilePlayer.hitbox_tr.X - TilePlayer.hitbox_bl.X),(TilePlayer.hitbox_tr.Y - TilePlayer.hitbox_bl.Y),
x*100,y*100,
100,100
))
{
map[1][x][y] = 255;
map[2][x][y] = 255;
TilePlayer.localtile.X = x;
TilePlayer.localtile.Y = y;
}
if(map[0][x][y] ^ map[screen+1][x][y])
{
map[screen+1][x][y] = map[0][x][y];
sprintf(tilenamebuffer,"%i",map[screen+1][x][y]);
draw_tile(tilenamebuffer,x*100,y*100);
udt++;
}
}
}
draw_sprite("lcarsblack",1000,DISPLAY_Y-164);
TilePlayer.rawtile = (TilePlayer.mapoffset.Y) + TilePlayer.localtile.Y + (TilePlayer.mapoffset.X * 100) + (TilePlayer.localtile.X * 100);
sprintf(textbuffer,"Tile:%i\nSprite:%i",TilePlayer.rawtile,fullmap[TilePlayer.rawtile]);
draw_spritetext(textbuffer, 1070, 950);
game2_tick_input();
draw_sprite("man",TilePlayer.location.X,TilePlayer.location.Y);
return 0;
}else{
/* screen_flipbuffer();
screen_clear();
game2_death();
return 1;*/
}
}
int game_hitbox_collide(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2)
{
if((x1 + w1) >= x2)
if(x1 <= (x2 + w2))
if((y1 + h1) >= y2)
if(y1 <= (y2 + h2))
return 1;
return 0;
}
void exitfunc () {
screen_flipbuffer();
screen_clear();
screen_flipbuffer();
screen_clear();
screen_nobuffer();
free(buffer);
free(fontbuffer);
free(tilebuffer);
}
int main(int argc, char *argv[])
{
int lastoutcome = 1;
int outcome = 0;
atexit(exitfunc);
// Set initial display mode
display_mode(DISPLAY_MODE);
screen_clear();
// Load sprite library
load_sprites("Spr",&buffer);
load_sprites("Font",&fontbuffer);
// Clear both buffers or we get gibberish
screen_flipbuffer();
screen_clear();
screen_flipbuffer();
screen_clear();
lastoutcome = 1;
load_sprites("Tiles",&tilebuffer);
// Mission 2
while(lastoutcome == 1)
{
outcome = 0;
screen_clear();
game2_setup();
while(!outcome)
{
outcome = game2_tick();
}
lastoutcome = outcome;
}
free(buffer);
return 0;
}
+14 -21
View File
@@ -32,6 +32,8 @@ struct TilePlayer_s {
struct EntityLocation_s hitbox_bl;
struct EntityLocation_s hitbox_tr;
struct EntityLocation_s mapoffset;
struct EntityLocation_s localtile;
int rawtile;
};
struct TilePlayer_s TilePlayer;
@@ -165,7 +167,7 @@ void game2_tick_input()
if(input_readkey(57))
{
TilePlayer.location.Y += 3 * (tick - lasttick);
if(TilePlayer.location.Y > (9*100))
if(TilePlayer.location.Y > (950))
{
TilePlayer.location.Y = 100;
TilePlayer.mapoffset.Y += 10;
@@ -176,7 +178,7 @@ void game2_tick_input()
if(input_readkey(41))
{
TilePlayer.location.Y -= 3 * (tick - lasttick);
if(TilePlayer.location.Y < (1*100))
if(TilePlayer.location.Y < (10))
{
TilePlayer.location.Y = 900;
TilePlayer.mapoffset.Y -= 10;
@@ -187,7 +189,7 @@ void game2_tick_input()
if(input_readkey(121))
{
TilePlayer.location.X += 3 * (tick - lasttick);
if(TilePlayer.location.X > (9*100))
if(TilePlayer.location.X > (950))
{
TilePlayer.location.X = 100;
TilePlayer.mapoffset.X += 10;
@@ -198,24 +200,12 @@ void game2_tick_input()
if(input_readkey(25))
{
TilePlayer.location.X -= 3 * (tick - lasttick);
if(TilePlayer.location.X < (1*100))
if(TilePlayer.location.X < (10))
{
TilePlayer.location.X = 900;
TilePlayer.mapoffset.X -= 10;
}
}
// Q
if(input_readkey(16))
{
for(x = 0; x < TILESX; x++)
{
for(y = 0; y < TILESY; y++)
{
map[0][x][y] = 1;
}
}
}
}
int game2_tick()
@@ -244,6 +234,8 @@ int game2_tick()
{
map[1][x][y] = 255;
map[2][x][y] = 255;
TilePlayer.localtile.X = x;
TilePlayer.localtile.Y = y;
}
if(map[0][x][y] ^ map[screen+1][x][y])
@@ -254,13 +246,14 @@ int game2_tick()
udt++;
}
}
//draw_sprite("lcarsblack",1000,DISPLAY_Y-164);
//sprintf(textbuffer,"CPF: %i\nUDT: %i",(tick-lasttick), udt);
//draw_spritetext(textbuffer, 1070, 950);
}
draw_sprite("lcarsblack",1000,DISPLAY_Y-164);
TilePlayer.rawtile = (TilePlayer.mapoffset.Y) + TilePlayer.localtile.Y + (TilePlayer.mapoffset.X * 100) + (TilePlayer.localtile.X * 100);
sprintf(textbuffer,"Tile:%i\nSprite:%i",TilePlayer.rawtile,fullmap[TilePlayer.rawtile]);
draw_spritetext(textbuffer, 1070, 950);
game2_tick_input();
draw_sprite("man",TilePlayer.location.X,TilePlayer.location.Y);