Added basic panning.
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
CC = gcc
|
||||
CFLAGS=-g -Wall -DDEBUG -Wpedantic -lSDL2 -lSDL2_ttf
|
||||
SRCDIR=src
|
||||
OBJDIR=obj
|
||||
SRCS=$(wildcard $(SRCDIR)/*.c)
|
||||
|
||||
# Substitute all .c with .o from SRCS
|
||||
OBJS=$(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(SRCS))
|
||||
BINDIR=bin
|
||||
BIN=$(BINDIR)/game
|
||||
|
||||
all: $(BIN)
|
||||
release: CFLAGS=-Wall -Wpedantic -O2 -lSDL2 -lSDL2_ttf
|
||||
release: clean
|
||||
release: $(BIN)
|
||||
|
||||
$(BIN): $(OBJS) $(BINDIR)
|
||||
$(CC) $(CFLAGS) $(OBJS) -o $@
|
||||
|
||||
$(OBJDIR)/%.o: $(SRCDIR)/%.c $(OBJDIR)
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
$(BINDIR):
|
||||
mkdir $@
|
||||
|
||||
$(OBJDIR):
|
||||
mkdir $@
|
||||
|
||||
.PHONY: clean
|
||||
.PHONY: test
|
||||
.PHONY: disass
|
||||
|
||||
clean:
|
||||
rm -rf $(BINDIR)/* $(OBJDIR)/*
|
||||
test:
|
||||
$(BIN)
|
||||
disass:
|
||||
objdump -S --disassemble $(OBJDIR)/$(FILE).o > $(OBJDIR)/$(FILE).s
|
||||
@@ -0,0 +1,7 @@
|
||||
#include "list.h"
|
||||
|
||||
#define DEFAULTLISTSIZE 64
|
||||
|
||||
List* CreateList(void) {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
#ifndef LIST_H
|
||||
#define LIST_H
|
||||
|
||||
typedef struct {
|
||||
unsigned int Capcity;
|
||||
unsigned int Size;
|
||||
char** Strings;
|
||||
} List;
|
||||
|
||||
List* CreateList(void);
|
||||
|
||||
#endif
|
||||
BIN
Binary file not shown.
+72
-1
@@ -1,3 +1,4 @@
|
||||
#include <SDL2/SDL_surface.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
@@ -19,6 +20,7 @@
|
||||
|
||||
const int SCREEN_WIDTH = 1280;
|
||||
const int SCREEN_HEIGHT = 720;
|
||||
int MouseDown = 0;
|
||||
|
||||
typedef struct {
|
||||
SDL_Window *window;
|
||||
@@ -30,6 +32,8 @@ App app;
|
||||
|
||||
void HandleInput(void);
|
||||
int Exit = 0;
|
||||
int XRel, YRel;
|
||||
int XOrg, YOrg;
|
||||
|
||||
void Cleanup(void) {
|
||||
SDL_DestroyWindow(app.window);
|
||||
@@ -41,6 +45,10 @@ void Cleanup(void) {
|
||||
|
||||
int main(int argc, char** argv){
|
||||
memset(&app, 0, sizeof(app));
|
||||
XRel = 0;
|
||||
YRel = 0;
|
||||
XOrg = 0;
|
||||
YOrg = 0;
|
||||
|
||||
atexit(Cleanup);
|
||||
|
||||
@@ -76,6 +84,60 @@ int main(int argc, char** argv){
|
||||
printf("Renderer failed: %s\n", SDL_GetError());
|
||||
return -1;
|
||||
}
|
||||
|
||||
//SDL_SetRelativeMouseMode(SDL_TRUE);
|
||||
|
||||
SDL_Rect rect;
|
||||
|
||||
rect.x = SCREEN_WIDTH / SCREEN_HEIGHT;
|
||||
rect.y = SCREEN_WIDTH / SCREEN_HEIGHT;
|
||||
rect.w = SCREEN_WIDTH / 2;
|
||||
rect.h = SCREEN_HEIGHT / 2;
|
||||
|
||||
SDL_Rect rect2;
|
||||
|
||||
rect2.x = 250;// / SCREEN_HEIGHT;
|
||||
rect2.y = 250;// / SCREEN_HEIGHT;
|
||||
rect2.w = SCREEN_WIDTH / 4;
|
||||
rect2.h = SCREEN_HEIGHT / 4;
|
||||
|
||||
// Uint64 start = 0;
|
||||
// Uint64 end = 0;
|
||||
// float frameCount = 0;
|
||||
// int count = 0;
|
||||
|
||||
while(!Exit) {
|
||||
//start = SDL_GetPerformanceCounter();
|
||||
|
||||
SDL_Delay(16);
|
||||
|
||||
HandleInput();
|
||||
|
||||
SDL_SetRenderDrawColor(app.renderer, 0, 0, 255, 0);
|
||||
|
||||
SDL_RenderClear(app.renderer);
|
||||
|
||||
// if (count >= 100) {
|
||||
// snprintf(buffer, sizeof(buffer), "FPS: %.2f", count / frameCount);
|
||||
// count = 0;
|
||||
// frameCount = 0;
|
||||
// }
|
||||
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 0);
|
||||
|
||||
SDL_RenderFillRect(app.renderer, &(SDL_Rect){rect.x + XRel, rect.y + YRel, rect.w, rect.h});
|
||||
|
||||
SDL_SetRenderDrawColor(app.renderer, 128, 0, 0, 0);
|
||||
|
||||
SDL_RenderFillRect(app.renderer, &(SDL_Rect){rect2.x + XRel, rect2.y + YRel, rect2.w, rect2.h});
|
||||
|
||||
SDL_RenderPresent(app.renderer);
|
||||
|
||||
// end = SDL_GetPerformanceCounter();
|
||||
|
||||
// frameCount += (end - start) / (float)SDL_GetPerformanceFrequency();
|
||||
|
||||
// count++;
|
||||
}
|
||||
}
|
||||
|
||||
void HandleInput(void) {
|
||||
@@ -83,11 +145,20 @@ void HandleInput(void) {
|
||||
while(SDL_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_QUIT:
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
Exit = 1;
|
||||
break;
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
MouseDown = 1;
|
||||
break;
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
MouseDown = 0;
|
||||
break;
|
||||
case SDL_MOUSEMOTION:
|
||||
//if (MainMenu->HitCheck(event.motion.x, event.motion.y, &MainMenu->Area)) {
|
||||
if (MouseDown){
|
||||
XRel += event.motion.xrel;
|
||||
YRel += event.motion.yrel;
|
||||
}
|
||||
case SDL_TEXTINPUT:
|
||||
case SDL_KEYDOWN:
|
||||
default:
|
||||
Reference in New Issue
Block a user