new menu. Ice not working

This commit is contained in:
Tituya 2021-05-04 01:46:11 +02:00
parent 6ed426c4f7
commit a4f600c1ff
10 changed files with 74 additions and 23 deletions

View File

@ -56,6 +56,7 @@ set(SOURCES
src/save.c
src/util.c
src/replace.c
src/friction.c
generated/setlevel.c
generated/times.c)
@ -76,7 +77,7 @@ set(ASSETS_cg
assets-cg/img/key1.png
assets-cg/img/key2.png
assets-cg/img/medals.png
assets-cg/img/menu.png
assets-cg/img/menu2.png
assets-cg/img/new.png
assets-cg/img/player.png
assets-cg/img/solid.png
@ -93,5 +94,6 @@ add_executable(${PROJECT_NAME} ${SOURCES} ${ASSETS} ${ASSETS_${FXSDK_PLATFORM}})
target_compile_options(${PROJECT_NAME} PRIVATE ${FLAGS})
target_link_libraries(${PROJECT_NAME} Gint::Gint)
target_link_options(${PROJECT_NAME} PRIVATE -Wl,-Map=map)
generate_g3a(TARGET ${PROJECT_NAME} OUTPUT "${PROJECT_NAME}.g3a"
NAME "${PROJECT_NAME}" ICONS assets-cg/icon-uns.png assets-cg/icon-sel.png)

View File

@ -71,4 +71,4 @@ nbswitch.png:
nbswitchlayout.png:
type:bopti-image
profile:p4
name: img_nbswitchlayout
name: img_nbswitchlayout

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 18 KiB

3
include/friction.h Normal file
View File

@ -0,0 +1,3 @@
float apply_friction(int x, int y, char level[]);
void mod_ice(int x, int y, char level[], float *friction);
void mod_solid(int x, int y, char level[], float *friction);

View File

@ -1,3 +1,5 @@
#pragma once
int round(float num);
int round_sup(float num);
int rand_range(int low, int high);

View File

@ -82,8 +82,8 @@ void collide_replace(int x, int y, char level[], char collide, char replace)
char collide_center(int x, int y, char level[], char block)
{
if (level[(int)((x + round(PLAYER_HEIGHT / 2)) / TILE_HEIGHT) +
(int)((y + round(PLAYER_HEIGHT / 2)) / TILE_HEIGHT) *
if (level[(int)((x + round_sup(PLAYER_HEIGHT / 2)) / TILE_HEIGHT) +
(int)((y + round_sup(PLAYER_HEIGHT / 2)) / TILE_HEIGHT) *
LEVEL_WIDTH] == block) {
return 1;
}

23
src/friction.c Normal file
View File

@ -0,0 +1,23 @@
#include "friction.h"
#include "collide.h"
float apply_friction(int x, int y, char level[]) {
float friction = 0.2;
mod_solid(x, y, level, &friction);
mod_ice(x, y, level, &friction);
return friction;
}
void mod_ice(int x, int y, char level[], float *friction) {
if (collide(x, y - 1, level, 'i') ||
collide(x, y + 1, level, 'i')) {
*friction = 0.15;
}
}
void mod_solid(int x, int y, char level[], float *friction) {
if(collide_solid(x, y - 1, level) ||
collide_solid(x, y + 1, level)) {
*friction = 0.2;
}
}

View File

@ -7,6 +7,7 @@
#include "setlevel.h"
#include "times.h"
#include "util.h"
#include "friction.h"
#include <gint/clock.h>
#include <gint/display.h>
#include <gint/gint.h>
@ -17,7 +18,7 @@
#define VACCELERATION 0.2
#define HACCELERATION 0.4
#define MAX_VSPD 9.0
#define FRICTION 0.2
#define MAX_HSPD 2.0
static int callback(volatile int *frame_elapsed);
static void end(unsigned int frame);
@ -156,6 +157,7 @@ static void game(int *id_level, char mode, char *type)
coin);
if (check_nbswitch)
draw_nbswitch(nbswitch);
dprint(330, 0, C_RED, "%d", (int)(hspd*100));
dupdate();
}
pollevent();
@ -168,14 +170,11 @@ static void game(int *id_level, char mode, char *type)
// right and left collision
if (keydown_any(KEY_RIGHT, KEY_LEFT, 0)) {
float hbuff = 0.0;
char signe = (keydown(KEY_RIGHT) - keydown(KEY_LEFT));
if (collide(player_x, player_y - 1, level, 'i') ||
collide(player_x, player_y + 1, level, 'i')) {
hbuff += 0.12;
}
hspd *= 1 - FRICTION;
hspd += signe * (HACCELERATION + hbuff);
float friction = apply_friction(player_x, player_y, level);
hspd *= 1 - friction;
hspd += signe * HACCELERATION;
if (!collide_solid(player_x + round(hspd) + signe * 1,
player_y, level))
player_x += round(hspd);
@ -404,14 +403,15 @@ static void game(int *id_level, char mode, char *type)
}
// warp
if (player_y >= 212)
if (player_y >= 210)
player_y = -4;
if (player_y < -6)
player_y = 212;
player_y = 209;
// Menu
if (keydown_any(KEY_EXIT, KEY_MENU, 0)) {
timer_pause(timer);
char menu_loop = 1;
char selected = 0;
int Y_POS = 18;
@ -446,6 +446,7 @@ static void game(int *id_level, char mode, char *type)
switch (selected) {
case 0:
menu_loop = 0;
timer_start(timer);
break;
case 1:
menu_loop = 0;
@ -467,6 +468,7 @@ static void game(int *id_level, char mode, char *type)
}
}
timer_stop(timer);
timer_wait(timer);
// when a level is quit
if (mode) {
if (*id_level == 0) {

View File

@ -17,21 +17,29 @@ enum MenuCode start_menu(char *type)
char selection = 0;
char buffer = 1;
char buffer2 = 1;
int Y_POS = 85;
int Y_POS = 145;
char level[351];
int start_x;
int start_y;
set_level(rand_range(1,LEVEL_MAX), level, &start_x, &start_y, NULL,
NULL, NULL, NULL);
while (menu_loop) {
clearevents();
dclear(C_WHITE);
draw_level(level);
dimage(0, 0, &img_menu);
selection += keydown(KEY_DOWN) - keydown(KEY_UP);
if (selection == 4)
selection = 0;
else if (selection == -1)
selection = 3;
dtext(32, Y_POS, C_BLACK, "PLAY");
dtext(32, Y_POS + 12, C_BLACK, "ALL MODE");
dtext(32, Y_POS + 24, C_BLACK, "TEST LEVEL");
dtext(32, Y_POS + 36, C_BLACK, "EXIT GAME");
dtext(16, Y_POS + (selection * 12), C_BLACK, ">");
dtext(160, Y_POS, C_WHITE, "PLAY");
dtext(160, Y_POS + 12, C_WHITE, "ALL MODE");
dtext(160, Y_POS + 24, C_WHITE, "TEST LEVEL");
dtext(160, Y_POS + 36, C_WHITE, "EXIT GAME");
dtext(145, Y_POS + (selection * 12), C_WHITE, ">");
dupdate();
if (keydown_any(KEY_SHIFT, KEY_EXE, 0)) {
if (!buffer2)
@ -85,7 +93,6 @@ char speed_menu(int *id_level)
dtext(340, 214, C_BLACK, "TIMES");
dtext(190, 45, C_BLACK, "Time : ");
dprint(80, 20, C_BLACK, "Level : %d", *id_level);
dprint(80, 50, C_RED, "%d", gravity);
if (sto != 0)
dprint(194, 60, C_RED, "%.2j", sto);
else

View File

@ -1,6 +1,18 @@
#include "util.h"
#include <gint/std/stdlib.h>
#include <gint/rtc.h>
int round(float num)
{
int round(float num) {
return (num < 0) ? (num - 0.5) : (num + 0.5);
}
int round_sup(float num) {
return (int)(num+1);
}
/*maybe illegal*/
int rand_range(int low, int high)
{
srand(rtc_ticks());
return (rand() % (high - low)) + low;
}