aboutsummaryrefslogtreecommitdiff
path: root/src/demo.c
blob: 5ab796da36b85ba726df873f3a691e2624b3da84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include <math.h>

#include "demo.h"
#include "ppu/ppu.h"
#include "input.h"
#include "ppu/internals.h"

#define HH_DEMO_BALL_COUNT 5
hh_s_ppu_loc_fam_entry g_hh_demo_balls[HH_DEMO_BALL_COUNT];

void hh_demo_setup() {
	// load sprites
	hh_ppu_update_sprite(1, HH_DBG_SPRITE_BALL);
	hh_ppu_update_sprite(2, HH_DBG_SPRITE_CHECKERBOARD);

	// background pattern
	hh_ppu_update_color(0, 0, (hh_ppu_rgb_color_t) {0x1, 0x1, 0x3});
	hh_ppu_update_color(0, 1, (hh_ppu_rgb_color_t) {0x4, 0x4, 0x6});
	for (unsigned i = 0; i < HH_PPU_BG_CANVAS_TILES_H * HH_PPU_BG_CANVAS_TILES_V; i++) {
		hh_ppu_update_background(i, (hh_s_ppu_loc_bam_entry) {
			.horizontal_flip = false,
			.vertical_flip = false,
			.palette_index = 0,
			.tilemap_index = 2,
		});
	}

	// cool colors
	hh_ppu_update_color(1, 1, (hh_ppu_rgb_color_t) {0xf, 0x0, 0xf});
	hh_ppu_update_color(2, 1, (hh_ppu_rgb_color_t) {0xf, 0xf, 0xf});
	hh_ppu_update_color(3, 1, (hh_ppu_rgb_color_t) {0xf, 0x0, 0x0});
	hh_ppu_update_color(4, 1, (hh_ppu_rgb_color_t) {0x0, 0xf, 0xf});
	hh_ppu_update_color(5, 1, (hh_ppu_rgb_color_t) {0x0, 0x0, 0xf});

	// balls
	for (unsigned i = 0; i < HH_DEMO_BALL_COUNT; i++) {
		g_hh_demo_balls[i].horizontal_flip = false;
		g_hh_demo_balls[i].vertical_flip = false;
		g_hh_demo_balls[i].palette_index = i+1;
		g_hh_demo_balls[i].tilemap_index = 1;
	}
	// hh_ppu_flush();
}

void hh_demo_loop(unsigned long frame) {
	// if (frame % 300 == 0) hh_demo_setup();
	//
	// if (frame > 1) return;
	// frame = 40;

	// set background pattern position
	hh_ppu_update_background_pos((frame / 5) % HH_PPU_SPRITE_WIDTH, (frame / 20) % HH_PPU_SPRITE_HEIGHT);

	for (unsigned i = 0; i < HH_DEMO_BALL_COUNT; i++) {
		g_hh_demo_balls[i].position_x = HH_PPU_SCREEN_WIDTH/2  - HH_PPU_SPRITE_WIDTH/2  + (int)(60 * (double)sin(1*((double)frame + 3*(double)i) / 10));
		g_hh_demo_balls[i].position_y = HH_PPU_SCREEN_HEIGHT/2 - HH_PPU_SPRITE_HEIGHT/2 + (int)(30 * (double)sin(2*((double)frame + 3*(double) i) / 10));
		hh_ppu_update_foreground(i+16, g_hh_demo_balls[i]);
	}
	hh_ppu_update_foreground(32, (hh_s_ppu_loc_fam_entry) {
		.horizontal_flip = false,
		.vertical_flip = false,
		.palette_index = g_hh_controller_p1.dpad_up * 2,
		.tilemap_index = 1,
		.position_x = 16,
		.position_y = 0,
	});
	hh_ppu_update_foreground(33, (hh_s_ppu_loc_fam_entry) {
		.horizontal_flip = false,
		.vertical_flip = false,
		.palette_index = g_hh_controller_p1.dpad_down * 2,
		.tilemap_index = 1,
		.position_x = 16,
		.position_y = 32,
	});
	hh_ppu_update_foreground(34, (hh_s_ppu_loc_fam_entry) {
		.horizontal_flip = false,
		.vertical_flip = false,
		.palette_index = g_hh_controller_p1.dpad_left * 2,
		.tilemap_index = 1,
		.position_x = 0,
		.position_y = 16,
	});
	hh_ppu_update_foreground(35, (hh_s_ppu_loc_fam_entry) {
		.horizontal_flip = false,
		.vertical_flip = false,
		.palette_index = g_hh_controller_p1.dpad_right * 2,
		.tilemap_index = 1,
		.position_x = 32,
		.position_y = 16,
	});
	hh_ppu_update_foreground(36, (hh_s_ppu_loc_fam_entry) {
		.horizontal_flip = false,
		.vertical_flip = false,
		.palette_index = g_hh_controller_p1.button_primary * 2,
		.tilemap_index = 1,
		.position_x = 88,
		.position_y = 16,
	});
	hh_ppu_update_foreground(37, (hh_s_ppu_loc_fam_entry) {
		.horizontal_flip = false,
		.vertical_flip = false,
		.palette_index = g_hh_controller_p1.button_secondary * 2,
		.tilemap_index = 1,
		.position_x = 64,
		.position_y = 16,
	});
}